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
"
^(.+?)[-. ]{0,3}s?(\d?\d)[ex](\d\d)[-. ]{0,3}(.*?)[-. ]?(?:(?=pulcione|eng|ita|\w+Mux|\w+dl|\d+p|XviD|NovaRip).+)?\.([\w]{2,3})$
"
img
^ asserts position at start of a line
1st Capturing Group
(.+?)
.
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)
Match a single character present in the list below
[-. ]
{0,3} matches the previous token between 0 and 3 times, as many times as possible, giving back as needed (greedy)
-.
matches a single character in the list -. (case insensitive)
s
matches the character s with index 11510 (7316 or 1638) literally (case insensitive)
2nd Capturing Group
(\d?\d)
\d
matches a digit (equivalent to [0-9])
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\d matches a digit (equivalent to [0-9])
Match a single character present in the list below
[ex]
ex
matches a single character in the list ex (case insensitive)
3rd Capturing Group
(\d\d)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
Match a single character present in the list below
[-. ]
{0,3} matches the previous token between 0 and 3 times, as many times as possible, giving back as needed (greedy)
-.
matches a single character in the list -. (case insensitive)
4th Capturing Group
(.*?)
.
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)
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 a single character in the list -. (case insensitive)
Non-capturing group
(?:(?=pulcione|eng|ita|\w+Mux|\w+dl|\d+p|XviD|NovaRip).+)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Positive Lookahead
(?=pulcione|eng|ita|\w+Mux|\w+dl|\d+p|XviD|NovaRip)
Assert that the Regex below matches
1st Alternative
pulcione
pulcione
matches the characters pulcione literally (case insensitive)
2nd Alternative
eng
eng
matches the characters eng literally (case insensitive)
3rd Alternative
ita
4th Alternative
\w+Mux
5th Alternative
\w+dl
6th Alternative
\d+p
7th Alternative
XviD
8th Alternative
NovaRip
.
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 the character . with index 4610 (2E16 or 568) literally (case insensitive)
5th Capturing Group
([\w]{2,3})
Match a single character present in the list below
[\w]
{2,3} matches the previous token between 2 and 3 times, as many times as possible, giving back as needed (greedy)
\w matches any word character (equivalent to [a-zA-Z0-9_])
$ asserts position at the end of a line
Global pattern flags
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
img

Test String