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
/
^\/\*-{78}\n(?<title> {4}.+?: .+\n)?[\n \t]+(?<desc>^ {4}(?:.+|\n)+?\n)?[\n \t]+(?<remarks>^ {4}(?:.+|\n)+?\n)?[\n \t]+(?<cols>^ {4}Columns:(?:.+|\n)+?\n)?[\n \t]+(?<cons>^ {4}Constraints:(?:.+|\n)+?\n)?[\n \t]+(?<tags>^ {4}Tags:(?:.+|\n)+?)?^\*\/ *\n
/
m
^ asserts position at start of a line
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
\* matches the character * with index 4210 (2A16 or 528) literally (case sensitive)
-
matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
\n matches a line-feed (newline) character (ASCII 10)
Named Capture Group title
(?<title> {4}.+?: .+\n)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
.
matches any character (except for line terminators)
+? matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
:
matches the characters : literally (case sensitive)
.
matches any character (except for line terminators)
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\n matches a line-feed (newline) character (ASCII 10)
Match a single character present in the list below
[\n \t]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\n matches a line-feed (newline) character (ASCII 10)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
\t matches a tab character (ASCII 9)
Named Capture Group desc
(?<desc>^ {4}(?:.+|\n)+?\n)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
^ asserts position at start of a line
matches the character with index 3210 (2016 or 408) literally (case sensitive)
Non-capturing group
(?:.+|\n)+?
+? matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
1st Alternative
.+
.
matches any character (except for line terminators)
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
2nd Alternative
\n
\n matches a line-feed (newline) character (ASCII 10)
\n matches a line-feed (newline) character (ASCII 10)
Match a single character present in the list below
[\n \t]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\n matches a line-feed (newline) character (ASCII 10)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
\t matches a tab character (ASCII 9)
Named Capture Group remarks
(?<remarks>^ {4}(?:.+|\n)+?\n)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
^ asserts position at start of a line
matches the character with index 3210 (2016 or 408) literally (case sensitive)
Non-capturing group
(?:.+|\n)+?
+? matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
1st Alternative
.+
.
matches any character (except for line terminators)
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
2nd Alternative
\n
\n matches a line-feed (newline) character (ASCII 10)
\n matches a line-feed (newline) character (ASCII 10)
Match a single character present in the list below
[\n \t]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\n matches a line-feed (newline) character (ASCII 10)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
\t matches a tab character (ASCII 9)
Named Capture Group cols
(?<cols>^ {4}Columns:(?:.+|\n)+?\n)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
^ asserts position at start of a line
matches the character with index 3210 (2016 or 408) literally (case sensitive)
Columns:
matches the characters Columns: literally (case sensitive)
Non-capturing group
(?:.+|\n)+?
+? matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
1st Alternative
.+
.
matches any character (except for line terminators)
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
2nd Alternative
\n
\n matches a line-feed (newline) character (ASCII 10)
\n matches a line-feed (newline) character (ASCII 10)
Match a single character present in the list below
[\n \t]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\n matches a line-feed (newline) character (ASCII 10)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
\t matches a tab character (ASCII 9)
Named Capture Group cons
(?<cons>^ {4}Constraints:(?:.+|\n)+?\n)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
^ asserts position at start of a line
matches the character with index 3210 (2016 or 408) literally (case sensitive)
Constraints:
matches the characters Constraints: literally (case sensitive)
Non-capturing group
(?:.+|\n)+?
\n matches a line-feed (newline) character (ASCII 10)
Match a single character present in the list below
[\n \t]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\n matches a line-feed (newline) character (ASCII 10)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
\t matches a tab character (ASCII 9)
Named Capture Group tags
(?<tags>^ {4}Tags:(?:.+|\n)+?)?
^ asserts position at start of a line
\* matches the character * with index 4210 (2A16 or 528) literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
\n matches a line-feed (newline) character (ASCII 10)
Global pattern flags
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.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
m

Test String