Regex escaping and flags: why the same pattern stops matching
A copied regex returns no matches when string escapes are pasted into the pattern field. Separate the pattern from the string that carries it, then add flags deliberately instead of changing several settings at once.
Open tool: Regex tester1. Test a capture group against two order IDs
Enter the Pattern value in the regex field, g in Flags and the Text value in the test input. Do not include the Pattern: label or slash delimiters. Expect two matches, with capture groups 104 and 205.
Pattern: order-(\d+)
Flags: g
Text: order-104 and order-2052. Strings add a layer of escaping
The pattern field receives raw regex text, so \d uses one backslash. JavaScript and JSON strings use two backslashes to represent it. These forms describe the same pattern but are not interchangeable as literal field input.
Raw pattern: order-(\d+)
JavaScript: new RegExp("order-(\\d+)", "g")
JSON: {"pattern":"order-(\\d+)","flags":"g"}3. Change one flag at a time
g continues searching after a match; i ignores case. Change one input to ORDER-205 and add i to observe that match returning. m changes how ^ and $ treat line boundaries; s allows the dot to match line breaks.
m and s solve different problems. Do not add both merely because input has multiple lines; identify the exact span you expect before choosing flags.
4. Check the regex dialect used by the target language
This tool uses the browser’s JavaScript RegExp. Some PCRE, Python or other engine syntax is incompatible, and browser support varies by version. After testing here, verify again in the language and version that actually run the code.
5. Check edge cases and execution cost
Beyond valid order IDs, test missing digits, case changes, boundaries and longer nonmatching text. The tool runs in a separate worker with timeout and match-count limits. A truncated result does not imply there are no more matches.
- Enter the pattern without duplicated string escapes or / delimiters.
- Check positive and negative cases, not only whether any match exists.
- Recheck syntax and performance in the actual runtime.