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
/
(?<ModelCode>\w{1})\((?<CountryCode>\w{3,4})\)\-(?<ModelNumber>\w{2})(\-(?<StackerType>\w{2}))? (?<InterfaceType>ID003\-\d{2})v(?<SoftwareVersion>\d{3}\-\d{2}) (?<SotfwareDate>\w+) (?<Crc>\w{4})
/
i
Named Capture Group ModelCode
(?<ModelCode>\w{1})
\w
matches any word character (equivalent to [a-zA-Z0-9_])
{1} matches the previous token exactly one time (meaningless quantifier)
\( matches the character ( with index 4010 (2816 or 508) literally (case insensitive)
Named Capture Group CountryCode
(?<CountryCode>\w{3,4})
\w
matches any word character (equivalent to [a-zA-Z0-9_])
{3,4} matches the previous token between 3 and 4 times, as many times as possible, giving back as needed (greedy)
\) matches the character ) with index 4110 (2916 or 518) literally (case insensitive)
\- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
Named Capture Group ModelNumber
(?<ModelNumber>\w{2})
\w
matches any word character (equivalent to [a-zA-Z0-9_])
{2} matches the previous token exactly 2 times
4th Capturing Group
(\-(?<StackerType>\w{2}))?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
Named Capture Group StackerType
(?<StackerType>\w{2})
\w
matches any word character (equivalent to [a-zA-Z0-9_])
{2} matches the previous token exactly 2 times
matches the character with index 3210 (2016 or 408) literally (case insensitive)
Named Capture Group InterfaceType
(?<InterfaceType>ID003\-\d{2})
ID003
matches the characters ID003 literally (case insensitive)
\- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
v matches the character v with index 11810 (7616 or 1668) literally (case insensitive)
Named Capture Group SoftwareVersion
(?<SoftwareVersion>\d{3}\-\d{2})
\d
matches a digit (equivalent to [0-9])
{3} matches the previous token exactly 3 times
\- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
matches the character with index 3210 (2016 or 408) literally (case insensitive)
Named Capture Group SotfwareDate
(?<SotfwareDate>\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)
matches the character with index 3210 (2016 or 408) literally (case insensitive)
Named Capture Group Crc
(?<Crc>\w{4})
\w
matches any word character (equivalent to [a-zA-Z0-9_])
{4} matches the previous token exactly 4 times
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