Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
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

/
/
gm

Test String

Code Generator

Generated Code

$re = '/(?i)(?:\w+\W+){0,9}?(?=.*(?:plot).*|.*(?:over).*)(?:\w+\W+){0,9}?(?=Charlie|Muir|Charlie Muir)\K(?:(?:Charlie|Muir|Charlie Muir)\s+)+/m'; $str = 'POSITIVE TESTING 1. Charlie Muir was over the moon. next next next next next next next next next next next next next next Charlie Muir was in the plot . next next next next next next next next next next next next next next 2. Charlie was over the moon. next next next next next next next next next next next next next next Charlie was in the plot . next next next next next next next next next next next next next next 3. Mr. Charlie was over the moon. next next next next next next next next next next next next next next Mr.Muir was in the plot. next next next next next next next next next next next next next next 4. When Charlie saw the letter , Charlie was over the moon. next next next next next next next next next next next next next next When Charlie saw the letter, ChaRLIE was walking in the plot. next next next next next next next next next next next next next next 5. When Charlie Muir saw letter , Charlie Muir was over the moon. next next next next next next next next next next next next next next When Charlie Muir saw letter, ChaRLIE MUIR was walking in plot. next next next next next next next next next next next next next next 6. When Muir saw letter , Mr.Muir was over the moon. next next next next next next next next next next next next next next When Mr.MUIR saw letter, Mr.CharliE was walking in plot. next next next next next next next next next next next next next next 7. When Muir saw letter , Mr.Charlie Muir was over the moon. next next next next next next next next next next next next next next When Mr.Charlie saw letter, Mr.MUIR was walking in plot. next next next next next next next next next next next next next next 8. Charlie Muir was Over the moon. next next next next next next next next next next next next next next Charlie Muir was in the PLOT . next next next next next next next next next next next next next next 9. He,Charlie and Muir were OVEr the moon. next next next next next next next next next next next next next next Charlie and MR.MUIR were in the ploT . next next next next next next next next next next next next next next 10. Over the moon was Charlie. next next next next next next next next next next next next next next Plot was far away from Charlie. next next next next next next next next next next next next next next 11. OVER the moon was Charlie Muir. next next next next next next next next next next next next next next Plot was far away from CHARLIE MUIR. next next next next next next next next next next next next next next 12. over the moon were Charlie and Muir. next next next next next next next next next next next next next next Plot was far away from Charlie and Muir. next next next next next next next next next next next next next next 13. Over the moon was Mr.Muir whose first name is Charlie. next next next next next next next next next next next next next next PLOT was far away from Charlie whose last name is MUIR. next next next next next next next next next next next next next next 14. OVER the moon was MUIR who is also charlie Muir. next next next next next next next next next next next next next next plot was far away from MUIR who is also CHarlie Muir. next next next next next next next next next next next next next next --------------------------------------------------------------------- POSITVE / NEGATIVE TESTING 15. Charlie knew when CHARLIE saw the letter that he would be over the moon after reading it. next next next next next next next next next next next next next next Charlie knew what the letter would contain when Charlie was reading it while walking in the plot. next next next next next next next next next next next next next next 16. Charlie knew when Charlie and muir saw the letter that they would be over the moon next next next next next next next next next next next next next next Charlie knew when Charlie and Muir saw the letter that they would be in the plot next next next next next next next next next next next next next next 17. Charlie knew when Charlie Muir saw the letter that they would be over the moon next next next next next next next next next next next next next next Charlie knew when Charlie Muir saw the letter that they would be in the plot next next next next next next next next next next next next next next 18. over the moon was Charlie Muir who is also known simply as CHARLIE. next next next next next next next next next next next next next next The plot was far away from Charlie Muir who is also known simply as CHARLIE. next next next next next next next next next next next next next next 19. OVER the moon was Mr.ChaRlie and Muir who are together known as the MuIr Brothers. next next next next next next next next next next next next next next The plot was far away from Charlie and Muir who are together known as the MUIR Brothers. next next next next next next next next next next next next next next ----------------------------------------------------------------------- NEGATIVE TESTING 20. Charlie Muir , after receiving and reading letter was addressed to him , was over the moon. next next next next next next next next next next next next next next Charlie Muir received and read the letter was addressed to him in plot. next next next next next next next next next next next next next next '; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php