Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
AI

The AI Prompt That Reviews Your Regex for Catastrophic Backtracking Before It Ships

- 26.09.26 - ErcanOPAK

🤖 The AI Prompt That Catches the Regex That Will Eventually Freeze Your Server

A regular expression can pass every test with normal input and still contain catastrophic backtracking – a specific pattern structure that causes execution time to explode exponentially on certain malicious or just unusually-shaped input, effectively freezing whatever thread runs it. This prompt asks an AI assistant to review a regex specifically for that risk before it ships.

đź“‹ The Prompt

Review this regular expression specifically for catastrophic
backtracking risk - not general correctness, specifically performance
under adversarial input.

For the pattern below:
1. Does it contain nested quantifiers or overlapping alternations that
   could cause exponential backtracking on certain inputs (e.g. (a+)+,
   (a|a)*, or similar structures)?
2. If a risk exists, describe a SPECIFIC input string that would trigger
   catastrophic slowdown, so I can verify it myself.
3. Suggest a rewritten version of the pattern that achieves the same
   matching behavior for legitimate input, without the backtracking risk.
4. Note whether this pattern is ever applied to user-supplied input
   (untrusted external strings) as opposed to only internal, controlled
   strings - the risk matters far more in the former case.

Pattern: [PASTE THE REGEX HERE]
Language/engine it runs in: [e.g. .NET, JavaScript, PCRE]'"'"'
Context: [where in the code this pattern is used, and what kind of
input it processes]

âś… Why This Prompt Works

  • Asking for a SPECIFIC triggering input rather than a general ‘yes this looks risky’ answer makes the finding verifiable – running that exact input against the pattern is a fast, concrete way to confirm the risk is real before spending time rewriting anything.
  • Specifying the regex engine and language matters because backtracking behavior genuinely differs between engines (some use different matching algorithms with different worst-case behavior) – a risk assessment that ignores which engine is running the pattern can miss engine-specific nuances entirely.
  • Asking specifically whether the pattern processes user-supplied input reframes this from an abstract code-quality question into a concrete security question – a backtracking risk in a pattern that only ever runs against trusted, internally-generated strings is a much lower priority than the same risk in a pattern validating public form input.

⚠️ Where to Draw the Line

  • A suggested rewrite needs to be tested against the same set of legitimate inputs the original pattern was meant to handle – a regex that avoids backtracking risk but no longer matches correctly isn’t actually a fix, it’s a different bug.
  • This prompt catches a specific, well-known category of regex risk – it isn’t a substitute for a broader security review of anywhere user input reaches the application, just one specific and often-overlooked piece of that larger picture.

A regex that’s correct on every test case you tried can still be one adversarial input away from freezing a thread – that gap is exactly what’s worth a second look before it ships.

— AI Power User

Related posts:

AI Prompt — Personal Decision Clarity

AI Prompt — Personal Decision Clarity

The AI Prompt That Turns a Closet Full of Clothes Into a Capsule Wardrobe You'll Actually Wear

The AI Prompt That Turns a Closet Full of Clothes Into a Capsule Wardrobe You'll Actually Wear

AI Prompt — Emergency Preparedness

AI Prompt — Emergency Preparedness

Views: 14
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

The AI Prompt That Turns a Stack of Config Files Into a Clear Diff of What Changed Between Environments
SQL Server: Why a Temp Table Inside a Stored Procedure Triggers Constant Recompilation

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,080 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 869 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 672 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 631 views
  8. 08Average of all values in a column that are not zero in SQL 585 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 562 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com