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?$|^(11+?)\1+$
"
1st Alternative
^1?$
^ asserts position at start of the string
1
matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
2nd Alternative
^(11+?)\1+$
^ asserts position at start of the string
1st Capturing Group
(11+?)
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
1
matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
\1
matches the same text as most recently matched by the 1st capturing group
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"

Test String