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<mesini>\d{2})(?P<diaini>\d{2})(?P<horaini>\d{2})(?P<minini>\d{2})\s(?P<duracaosegundo>\d{5})\s\d{4}\s(\w|\s)\s{6}\d\s(?<rota>\d{4})\s{6,13}(?<numerob>\d{8,20})\s(?<ramal>\d{4,8})\s{20,24}(?P<senha>(\d{6}|\s{6}))\s{8}\d{2}\s(?<tronco>\d{5})(?<nodetrunk>\d{4})\n
/
gm
Named Capture Group mesini
(?P<mesini>\d{2})
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
Named Capture Group diaini
(?P<diaini>\d{2})
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
Named Capture Group horaini
(?P<horaini>\d{2})
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
Named Capture Group minini
(?P<minini>\d{2})
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
Named Capture Group duracaosegundo
(?P<duracaosegundo>\d{5})
\d
matches a digit (equivalent to [0-9])
{5} matches the previous token exactly 5 times
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
\d
matches a digit (equivalent to [0-9])
{4} matches the previous token exactly 4 times
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
6th Capturing Group
(\w|\s)
1st Alternative
\w
\w matches any word character (equivalent to [a-zA-Z0-9_])
2nd Alternative
\s
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
{6} matches the previous token exactly 6 times
\d matches a digit (equivalent to [0-9])
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
Named Capture Group rota
(?<rota>\d{4})
\d
matches a digit (equivalent to [0-9])
{4} matches the previous token exactly 4 times
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
{6,13} matches the previous token between 6 and 13 times, as many times as possible, giving back as needed (greedy)
Named Capture Group numerob
(?<numerob>\d{8,20})
\d
matches a digit (equivalent to [0-9])
{8,20} matches the previous token between 8 and 20 times, as many times as possible, giving back as needed (greedy)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
Named Capture Group ramal
(?<ramal>\d{4,8})
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
Named Capture Group senha
(?P<senha>(\d{6}|\s{6}))
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
\d
matches a digit (equivalent to [0-9])
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
Named Capture Group tronco
(?<tronco>\d{5})
Named Capture Group nodetrunk
(?<nodetrunk>\d{4})
\n matches a line-feed (newline) character (ASCII 10)
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)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
gm

Test String