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
/
^\s*(?:(?:kind(?:est)* )*regards?|cheers?|greetings?|thanks|thank you)\b,?.*[\r\n]{0,2}.*(?:[.!?: ]*|$)
/
gim
^ asserts position at start of a line
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?:(?:kind(?:est)* )*regards?|cheers?|greetings?|thanks|thank you)
1st Alternative
(?:kind(?:est)* )*regards?
Non-capturing group
(?:kind(?:est)* )*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
kind
matches the characters kind literally (case insensitive)
Non-capturing group
(?:est)*
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
est
matches the characters est literally (case insensitive)
matches the character with index 3210 (2016 or 408) literally (case insensitive)
regard
matches the characters regard literally (case insensitive)
s
matches the character s with index 11510 (7316 or 1638) literally (case insensitive)
2nd Alternative
cheers?
cheer
matches the characters cheer literally (case insensitive)
s
matches the character s with index 11510 (7316 or 1638) literally (case insensitive)
3rd Alternative
greetings?
greeting
matches the characters greeting literally (case insensitive)
s
matches the character s with index 11510 (7316 or 1638) literally (case insensitive)
4th Alternative
thanks
thanks
matches the characters thanks literally (case insensitive)
5th Alternative
thank you
thank you
matches the characters thank you literally (case insensitive)
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
,
matches the character , with index 4410 (2C16 or 548) literally (case insensitive)
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[\r\n]
{0,2} matches the previous token between 0 and 2 times, as many times as possible, giving back as needed (greedy)
\r matches a carriage return (ASCII 13)
\n matches a line-feed (newline) character (ASCII 10)
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?:[.!?: ]*|$)
1st Alternative
[.!?: ]*
Match a single character present in the list below
[.!?: ]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
.!?:
matches a single character in the list .!?: (case insensitive)
2nd Alternative
$
$ asserts position at the end of a line
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])
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.

Regular Expression
No Match

/
/
gim

Test String

Code Generator

Generated Code

Loading code sample...
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report.
For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions