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
/
\* STATUS (?|(?:\"([^\r\n]+)\")|(\S+)|(?:\{\d+\}\r\n(.*))) \(MESSAGES (\d+) UNSEEN (\d+)\)
/
gi
\* matches the character * with index 4210 (2A16 or 528) literally (case insensitive)
STATUS
matches the characters STATUS literally (case insensitive)
Branch Reset Group
(?|(?:\"([^\r\n]+)\")|(\S+)|(?:\{\d+\}\r\n(.*)))
Subpatterns declared within each alternative of this construct will start over from the same index.
1st Alternative
(?:\"([^\r\n]+)\")
Non-capturing group
(?:\"([^\r\n]+)\")
\" matches the character " with index 3410 (2216 or 428) literally (case insensitive)
1st Capturing Group
([^\r\n]+)
Match a single character not present in the list below
[^\r\n]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\r matches a carriage return (ASCII 13)
\n matches a line-feed (newline) character (ASCII 10)
\" matches the character " with index 3410 (2216 or 428) literally (case insensitive)
2nd Alternative
(\S+)
1st Capturing Group
(\S+)
\S
matches any non-whitespace character (equivalent to [^\r\n\t\f\v ])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
3rd Alternative
(?:\{\d+\}\r\n(.*))
Non-capturing group
(?:\{\d+\}\r\n(.*))
\{ matches the character { with index 12310 (7B16 or 1738) literally (case insensitive)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\} matches the character } with index 12510 (7D16 or 1758) literally (case insensitive)
\r matches a carriage return (ASCII 13)
\n matches a line-feed (newline) character (ASCII 10)
1st Capturing Group
(.*)
.
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 3210 (2016 or 408) literally (case insensitive)
\( matches the character ( with index 4010 (2816 or 508) literally (case insensitive)
MESSAGES
matches the characters MESSAGES literally (case insensitive)
2nd Capturing Group
(\d+)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
UNSEEN
matches the characters UNSEEN literally (case insensitive)
3rd Capturing Group
(\d+)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\) matches the character ) with index 4110 (2916 or 518) literally (case insensitive)
Global pattern flags
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

/
/
gi

Test String