Flags change the rules
The same pattern behaves differently with different flags. Global keeps searching after the first hit; case-insensitive folds letters; multiline makes anchors match each line rather than the whole text; dot-all lets the period cross newlines; Unicode mode handles code points so Chinese and emoji behave; sticky starts only where the last match ended, suiting incremental parsing. Six checkboxes, and mis-ticking one is this tool's commonest frustration.
Steps
- Enter the pattern body without slash delimiters.
- Paste test text, multiline supported.
- Tick the flags you need.
- Provide replacement text using $1, $2, $& for the whole match, and prefix or suffix references.
- Run to see highlights and the rewritten result, then reset, copy or download.
Groups and backreferences
Parentheses capture, numbered from one in left-to-right opening order. Non-capturing groups use the question-colon form and consume no number. Named groups survive refactoring better, referenced by name in the replacement. Lookahead asserts what follows without consuming, handy for password rules, while lookbehind asserts what precedes and demands fixed width.
Greedy versus lazy
Quantifiers are greedy by default; adding a question mark makes them stop early. A greedy div pattern swallows everything to the final closing tag, while the lazy form matches tag by tag. Backtracking is the cost: nested quantifiers grow exponentially, and a few kilobytes of hostile input can freeze the browser — catastrophic backtracking — so prefer specific character classes over broad wildcards.
Common mistakes
Forgetting to escape metacharacters. Handling emoji without Unicode mode, where surrogate halves misalign matches. Expecting a period to cross lines without dot-all. Miscounting capture groups, which follow opening order. Using backslash references in a JavaScript-style replacement. And validating whole strings without anchors, since regex matches anywhere by default.
Performance and upkeep:Prefer character classes to dots and anchored prefixes to free searches. Global replacement on long text can slow down. Complex patterns benefit from comments and composition, with several simple patterns beating one monolith. Email, URL and phone validation only reject the obviously wrong; real checks need delivery tests or server rules. Against ReDoS from user input, cap length or add a timeout.