Regex Replace and Transform

Rewrite text with group references and replacer functions.

  • regex replace
  • re.sub
  • group reference
  • strip html
  • replacer function

Regex Replace and Transform

Rewrite text with group references and replacer functions.

Commands

CommandWhat it does
swap groups in JSUse dollar-1 references in replace
swap groups in PythonUse backslash-1 in re.sub
collapse whitespaceReplace runs of spaces with one
strip simple tagsRemove angle-bracket markup
function replacerCompute replacements with code

Example

'2026-10-11'.replace(/(\d{4})-(\d{2})-(\d{2})/, '$3/$2/$1')

FAQ

Why did my group reference insert literally?

The pattern had no such group, or you used a non-capturing group - count groups or switch to named ones.

Is stripping HTML with regex safe?

Only for trivial snippets; nested markup needs a real parser.

常見問題

Why did my group reference insert literally?
The pattern had no such group, or you used a non-capturing group - count groups or switch to named ones.
Is stripping HTML with regex safe?
Only for trivial snippets; nested markup needs a real parser.

Regex