Regular Expressions 101

Save & Share

  • Save Regex
    ctrl+s
  • Update Regex
    ctrl+⇧+s

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
^[a-z]{1,3}-[a-z]{1,2}-(\d){1,4}$
/
i
^ asserts position at start of the string
Match a single character present in the list below
[a-z]
{1,3} matches the previous token between 1 and 3 times, as many times as possible, giving back as needed (greedy)
a-z matches a single character in the range between a (index 97) and z (index 122) (case insensitive)
- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
Match a single character present in the list below
[a-z]
{1,2} matches the previous token between 1 and 2 times, as many times as possible, giving back as needed (greedy)
a-z matches a single character in the range between a (index 97) and z (index 122) (case insensitive)
- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
1st Capturing Group
(\d){1,4}
{1,4} matches the previous token between 1 and 4 times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
\d matches a digit (equivalent to [0-9])
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
Global pattern flags
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
i

Test String

Code Generator

Generated Code

Loading code sample...
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