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

// include the latest version of the regex crate in your Cargo.toml extern crate regex; use regex::Regex; fn main() { let regex = Regex::new(r"(?mx)String\.fromCharCode[^()]* ( \( (?:[^()]|(?1))* \) )").unwrap(); let string = " 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. I'm actually trying to deobfuscate a js file with python, and I have this kind of string that I want to \"scrap\" : String.fromCharCode ( (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) ) 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. 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)) EDIT: 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. "; // result will be an iterator over tuples containing the start and end indices for each match in the string let result = regex.captures_iter(string); for mat in result { println!("{:?}", mat); } }

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 Rust, please visit: https://docs.rs/regex/latest/regex/