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
/
^(?:[[:^print:][:cntrl:]\s]|GIF89.{0,20})*(?:<[^>]+>\s*)+<title>excel\s*online\s*\-\s*\w+<\/title>\s*<style(?:[^>]+>\s*)?<\!(?:[^>]+>\s*)?<\/style>
/
gis
^ asserts position at start of the string
Non-capturing group
(?:[[:^print:][:cntrl:]\s]|GIF89.{0,20})*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
1st Alternative
[[:^print:][:cntrl:]\s]
Match a single character present in the list below
[[:^print:][:cntrl:]\s]
[:^print:] matches the negation of print
[:cntrl:] matches a control character [\x00-\x1F\x7F]
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
2nd Alternative
GIF89.{0,20}
GIF89
matches the characters GIF89 literally (case insensitive)
.
matches any character
{0,20} matches the previous token between 0 and 20 times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?:<[^>]+>\s*)+
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
< matches the character < with index 6010 (3C16 or 748) literally (case insensitive)
Match a single character not present in the list below
[^>]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
> matches the character > with index 6210 (3E16 or 768) literally (case insensitive)
> matches the character > with index 6210 (3E16 or 768) literally (case insensitive)
\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)
<title>excel
matches the characters <title>excel literally (case insensitive)
\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)
online
matches the characters online literally (case insensitive)
\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)
\- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
\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)
\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 6010 (3C16 or 748) literally (case insensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case insensitive)
title>
matches the characters title> literally (case insensitive)
\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)
<style
matches the characters <style literally (case insensitive)
Non-capturing group
(?:[^>]+>\s*)?
< matches the character < with index 6010 (3C16 or 748) literally (case insensitive)
\! matches the character ! with index 3310 (2116 or 418) literally (case insensitive)
Non-capturing group
(?:[^>]+>\s*)?
< matches the character < with index 6010 (3C16 or 748) literally (case insensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case insensitive)
style>
matches the characters style> literally (case insensitive)
Global pattern flags
g modifier: global. All matches (don't return after first match)
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
s modifier: single line. Dot matches newline characters
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
gis

Test String