Regular Expressions 101

Save & Share

  • Save Regex
    ctrl+s
  • Update Regex
    ctrl+⇧+s

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8

Function

  • Match
  • Substitution
  • List
  • Unit Tests
"
^ Student\ number,\ Name[\n\r] (?P<student_names>(?:^\d+.+[\n\r])+) \s* ^ Student\ number,\ Score[\n\r] (?P<student_scores>(?:^\d+.+[\n\r])+)
"
gmx
^ asserts position at start of a line
Student
matches the characters Student literally (case sensitive)
\ matches the character with index 3210 (2016 or 408) literally (case sensitive)
number,
matches the characters number, literally (case sensitive)
\ matches the character with index 3210 (2016 or 408) literally (case sensitive)
Name
matches the characters Name literally (case sensitive)
Match a single character present in the list below
[\n\r]
\n matches a line-feed (newline) character (ASCII 10)
\r matches a carriage return (ASCII 13)
Named Capture Group student_names
(?P<student_names>(?:^\d+.+[\n\r])+)
Non-capturing group
(?:^\d+.+[\n\r])+
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
^ asserts position at start of a line
\d
matches a digit (equivalent to [0-9])
+ 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 one and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[\n\r]
\n matches a line-feed (newline) character (ASCII 10)
\r matches a carriage return (ASCII 13)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v  ])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
^ asserts position at start of a line
Student
matches the characters Student literally (case sensitive)
\ matches the character with index 3210 (2016 or 408) literally (case sensitive)
number,
matches the characters number, literally (case sensitive)
\ matches the character with index 3210 (2016 or 408) literally (case sensitive)
Score
matches the characters Score literally (case sensitive)
Match a single character present in the list below
[\n\r]
\n matches a line-feed (newline) character (ASCII 10)
\r matches a carriage return (ASCII 13)
Named Capture Group student_scores
(?P<student_scores>(?:^\d+.+[\n\r])+)
Non-capturing group
(?:^\d+.+[\n\r])+
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
^ asserts position at start of a line
\d
matches a digit (equivalent to [0-9])
+ 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)
Match a single character present in the list below
[\n\r]
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)
x modifier: extended. Spaces and text after a # in the pattern are ignored
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
gmx

Test String