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
"
(?P<first>^(?P<intend>\s*?)diagGetParameterRaw.+?(?P<diagresp>\w.+?),.*?\"SecurityClass\", (?P<first_rest>.+?;(?P<newline>[\n\r]+)))(?P<second>(?P<second_start>\s*?_DiagGenerateKeyFromSeed.+.?buffer,).+?(?P<second_rest>0x\d+?,.+))
"
gmi
Named Capture Group first
(?P<first>^(?P<intend>\s*?)diagGetParameterRaw.+?(?P<diagresp>\w.+?),.*?\"SecurityClass\", (?P<first_rest>.+?;(?P<newline>[\n\r]+)))
^ asserts position at start of a line
Named Capture Group intend
(?P<intend>\s*?)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
diagGetParameterRaw
matches the characters diagGetParameterRaw literally (case insensitive)
.
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)
Named Capture Group diagresp
(?P<diagresp>\w.+?)
\w matches any word character (equivalent to [a-zA-Z0-9_])
.
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 character , with index 4410 (2C16 or 548) literally (case insensitive)
.
matches any character (except for line terminators)
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
\" matches the character " with index 3410 (2216 or 428) literally (case insensitive)
SecurityClass
matches the characters SecurityClass literally (case insensitive)
\" matches the character " with index 3410 (2216 or 428) literally (case insensitive)
,
matches the characters , literally (case insensitive)
Named Capture Group first_rest
(?P<first_rest>.+?;(?P<newline>[\n\r]+))
.
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 character ; with index 5910 (3B16 or 738) literally (case insensitive)
Named Capture Group newline
(?P<newline>[\n\r]+)
Match a single character present in the list below
[\n\r]
+ 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)
\r matches a carriage return (ASCII 13)
Named Capture Group second
(?P<second>(?P<second_start>\s*?_DiagGenerateKeyFromSeed.+.?buffer,).+?(?P<second_rest>0x\d+?,.+))
Named Capture Group second_start
(?P<second_start>\s*?_DiagGenerateKeyFromSeed.+.?buffer,)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
_DiagGenerateKeyFromSeed
matches the characters _DiagGenerateKeyFromSeed literally (case insensitive)
.
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)
.
matches any character (except for line terminators)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
buffer,
matches the characters buffer, literally (case insensitive)
.
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)
Named Capture Group second_rest
(?P<second_rest>0x\d+?,.+)
0x
matches the characters 0x literally (case insensitive)
\d
matches a digit (equivalent to [0-9])
+? matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
, matches the character , with index 4410 (2C16 or 548) literally (case insensitive)
.
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)
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)
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
gmi

Test String

Substitution

Processing...