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
/
(\bByVal\b|\bByRef\b)? +(\w+)(?: +as +(\w+))?(?: *= *[\w"]+)? *[\)|,]?
/
i
1st Capturing Group
(\bByVal\b|\bByRef\b)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative
\bByVal\b
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
ByVal
matches the characters ByVal literally (case insensitive)
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
2nd Alternative
\bByRef\b
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
ByRef
matches the characters ByRef literally (case insensitive)
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
matches the character with index 3210 (2016 or 408) literally (case insensitive)
2nd Capturing Group
(\w+)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?: +as +(\w+))?
? 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 insensitive)
as
matches the characters as literally (case insensitive)
matches the character with index 3210 (2016 or 408) literally (case insensitive)
3rd Capturing Group
(\w+)
\w
matches any word character (equivalent to [a-zA-Z0-9_])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?: *= *[\w"]+)?
? 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 insensitive)
= matches the character = with index 6110 (3D16 or 758) literally (case insensitive)
matches the character with index 3210 (2016 or 408) literally (case insensitive)
Match a single character present in the list below
[\w"]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\w matches any word character (equivalent to [a-zA-Z0-9_])
" matches the character " with index 3410 (2216 or 428) literally (case insensitive)
matches the character with index 3210 (2016 or 408) literally (case insensitive)
Match a single character present in the list below
[\)|,]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\) matches the character ) with index 4110 (2916 or 518) literally (case insensitive)
|,
matches a single character in the list |, (case insensitive)
Global pattern flags
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

/
/
i

Test String