Regex Code Generator
Paste a pattern and get ready-to-paste code in several languages.
About this tool
Type the pattern the way you would in JavaScript, with flags such as g, i, m and s, and you get a matching snippet for JavaScript, Python, PHP and Java. Each language's string is escaped properly, so a pattern containing quotes, slashes or backslashes still pastes in correctly. The flags are translated too: i, m and s become re.IGNORECASE, re.MULTILINE and re.DOTALL in Python, the matching PHP modifiers and the Java Pattern constants. With g on, each snippet loops over every match (matchAll, finditer, preg_match_all, while (matcher.find())) rather than stopping at the first. Named groups are rewritten into Python's (?P<name>…) form, and a note appears below the code when something doesn't carry across exactly.