Regular Expressions 101

Save & Manage Regex

  • Current Version: 2
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression
Processing...

Test String

Code Generator

Generated Code

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "String\\.fromCharCode[^()]*\n" + "(\n" + " \\(\n" + " (?:[^()]|(?1))*\n" + " \\)\n" + ")"; final String string = "\n\n\n" + "I already saw this answer : How to get parentheses inside parentheses but it didn't really work if I don't know the number of levels of those parentheses.\n\n" + "I'm actually trying to deobfuscate a js file with python, and I have this kind of string that I want to \"scrap\" :\n\n" + "String.fromCharCode\n" + " (\n" + " (010 * 12 + 6),\n" + " (06 * (0x1 * (1 * 0xa + 6) + 1) + 12),\n" + " (4 * 27 + 3),\n" + " (01 * 0x3b + 50),\n" + " (1 * 0x34 + 15),\n" + " (1 * (1 * (3 * ((0x1 * 8 + 7) * 1 + 0) + 8) + 24) + 27),\n" + " (0x1 * (2 * 0x25 + 7) + 16),\n" + " (1 * 0112 + 40),\n" + " (1 * 0x2c + 23),\n" + " (0x3 * 042 + 9),\n" + " (1 * ((05 * 4 + 1) * 03 + 0) + 37),\n" + " (0x2 * (1 * 0x1f + 4) + 31)\n" + " )\n\n" + "When I run : re.findall(r\"String.fromCharCode\\((.+?)\\)\", content) it returns me String.fromCharCode((03 * (07 * 4 + 3) at first. So it seems like my line of code is only searching for the first occurrence of a closed parenthesis. I didn't try the answer of the above link but it seems like to not be \"infinite\", we should know beforehand the number of levels.\n\n" + "And what I want to get is the whole parenthesis like that : ((010 * 12 + 6),(06 * (0x1 * (1 * 0xa + 6) + 1) + 12),(4 * 27 + 3),(01 * 0x3b + 50),(1 * 0x34 + 15),(1 * (1 * (3 * ((0x1 * 8 + 7) * 1 + 0) + 8) + 24) + 27),(0x1 * (2 * 0x25 + 7) + 16),(1 * 0112 + 40),(1 * 0x2c + 23),(0x3 * 042 + 9),(1 * ((05 * 4 + 1) * 03 + 0) + 37),(0x2 * (1 * 0x1f + 4) + 31))\n\n" + "EDIT:\n\n" + "To clarify, the code have many other occurrence of the \"String.fromCharCode\" that is above. If I were to delete the ? in the regex code, it will retrieve the entire code.\n\n" + " "; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.COMMENTS); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html