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 (3)
`
(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)\([\w\-]+\):\s.*
`
gm
1st Capturing Group
(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)
1st Alternative
build
build
matches the characters build literally (case sensitive)
2nd Alternative
ci
ci
matches the characters ci literally (case sensitive)
3rd Alternative
docs
docs
matches the characters docs literally (case sensitive)
4th Alternative
feat
feat
matches the characters feat literally (case sensitive)
5th Alternative
fix
fix
matches the characters fix literally (case sensitive)
6th Alternative
perf
perf
matches the characters perf literally (case sensitive)
7th Alternative
refactor
refactor
matches the characters refactor literally (case sensitive)
8th Alternative
style
style
matches the characters style literally (case sensitive)
9th Alternative
test
test
matches the characters test literally (case sensitive)
10th Alternative
chore
chore
matches the characters chore literally (case sensitive)
11th Alternative
revert
revert
matches the characters revert literally (case sensitive)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
Match a single character present in the list below
[\w\-]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\w matches any word character (equivalent to [a-zA-Z0-9_])
\- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Global pattern flags
g modifier: global. All matches (don't return after first match)
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
Your regular expression does not match the subject string.

Regular Expression
No Match

`
`
gm

Test String