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
/
(^1\|.*)|(.*\|1\|.*)|(.*\|1$)
/
mg
1st Alternative
(^1\|.*)
1st Capturing Group
(^1\|.*)
^ asserts position at start of a line
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
\| matches the character | with index 12410 (7C16 or 1748) literally (case sensitive)
.
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)
2nd Alternative
(.*\|1\|.*)
2nd Capturing Group
(.*\|1\|.*)
.
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)
\| matches the character | with index 12410 (7C16 or 1748) literally (case sensitive)
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
\| matches the character | with index 12410 (7C16 or 1748) literally (case sensitive)
.
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)
3rd Alternative
(.*\|1$)
3rd Capturing Group
(.*\|1$)
.
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)
\| matches the character | with index 12410 (7C16 or 1748) literally (case sensitive)
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
$ 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)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
mg

Test String