Regular Expressions 101

@regex101
Donate
Sponsor
Contact
Bug Reports & Feedback
Wiki
Whats new?

Save & Share

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

Flavor

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

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
^#([a-f0-9]|[a-f0-9])$
/
mgi
^ asserts position at start of a line
#
matches the character # literally (case insensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Capturing Group
([a-f0-9]|[a-f0-9])
1st Alternative
[a-f0-9]
Match a single character present in the list below
[a-f0-9]
{6} matches the previous token exactly 6 times
a-f matches a single character in the range between a (index 97) and f (index 102) (case insensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case insensitive)
2nd Alternative
[a-f0-9]
Match a single character present in the list below
[a-f0-9]
{3} matches the previous token exactly 3 times
a-f matches a single character in the range between a (index 97) and f (index 102) (case insensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case insensitive)
$ asserts position at the end of a line
Global pattern flags
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
g modifier: global. All matches (don't return after first match)
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

/
/
mgi

Test String