Regular Expressions 101

Save & Share

Flavor

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

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
^(?:[[:xdigit:]]{2}([-:]))(?:[[:xdigit:]]{2}\1){4}[[:xdigit:]]{2}$
/
^ asserts position at start of the string
Non-capturing group
(?:[[:xdigit:]]{2}([-:]))
Match a single character present in the list below
[[:xdigit:]
[:xdigit:
matches a single character in the list [:xdigt (case sensitive)
]
matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
1st Capturing Group
([-:])
Match a single character present in the list below
[-:]
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
This hyphen is treated literally, which might be confusing for others. Consider escaping it or placing at the start or end of the class!
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
Non-capturing group
(?:[[:xdigit:]]{2}\1){4}
{4} matches the previous token exactly 4 times
Match a single character present in the list below
[[:xdigit:]
[:xdigit:
matches a single character in the list [:xdigt (case sensitive)
]
matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
\1 matches the same text as most recently matched by the 1st capturing group
Match a single character present in the list below
[[:xdigit:]
[:xdigit:
matches a single character in the list [:xdigt (case sensitive)
]
matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
$ asserts position at the end of the string
Your regular expression does not match the subject string.

Regular Expression
No Match

/
/

Test String