[abc] |
A single character of: a, b or c |
[^abc] |
Any single character except: a, b, or c |
[a-z] |
Any single character in the range a-z |
[a-zA-Z] |
Any single character in the range a-z or A-Z |
^ |
Start of string |
$ |
End of string |
\A |
Start of string |
\z |
End of string |
. |
Any single character |
\s |
Any whitespace character |
\S |
Any non-whitespace character |
\d |
Any digit |
\D |
Any non-digit |
\w |
Any word character (letter, number, underscore) |
\W |
Any non-word character |
\b |
A word boundary |
(...) |
Capture everything enclosed |
(a|b) |
a or b |
a? |
Zero or one of a |
a* |
Zero or more of a |
a+ |
One or more of a |
a{3} |
Exactly 3 of a |
a{3,} |
3 or more of a |
a{3,6} |
Between 3 and 6 of a |
(?:...) |
Non-capturing group |
(?>...) |
Atomic group (does not backtrack) |
(?|...) |
Duplicate subpattern group. |
(?#...) |
Comment |
(?'name'...) |
Named capturing group |
(?<name>...) |
Named capturing group |
(?P<name>...) |
Named capturing group |
(?JismxXU) |
Inline modifiers |
(?(...)..|..) |
Conditional (IF) statement |
(?R) |
Recurse the entire pattern |
(?1) |
Recurse the first subpattern |
(?=...) |
Positive Lookahead |
(?<=...) |
Positive Lookbehind |
(?!...) |
Negative Lookahead |
(?<!...) |
Negative Lookbehind |
(*...) |
Verbs |
[abc]* |
0 or more of a, b or c [greedy] |
[abc]*+ |
0 or more of a, b or c [possessive] |
[abc]*? |
Zero or more of a, b or c [lazy] |
\Q...\E |
Quote; Treat as literals |
[[:alnum:]] |
Posix style char class |
\G |
Special anchor, useful with /g |
\B |
Negated word boundary |
\p{..} or \p.. |
Unicode character properties |
-
How do I match several test cases?
This is easy! Use the ^$ anchors in your expressions, combined with the multine flag! This will treat each line in the textarea above as an independent 'test case' if you will. -
Where can I read more about regular expressions?
Besides the quiz we offer here on the website I highly recommend http://www.regular-expressions.info/. Another great read is the Regular Expressions Cookbook which unfortunately is not free. -
What does the numbers [5-7] mean in the Match result?
There numbers show the start and end offset (in bytes) respectively where the engine found the result. -
Can I save or share my work?
You can always create a permalink and use it in any way you like. Creating a permalink will store your data to a database. Make sure you read our privacy policy. You can also directly use URL-encoded values and do: http://www.regex101.com/?regex=...&options=...&text=...&sub=...
If you're up for it, submit it to the community
Understanding lookarounds
Lookbehinds are fixed width, meaning you can not use any quantifiers (+, ?, *, {m,n}). Lookarounds are also zero-width assertions, meaning they do not consume what they match.
Babewatching
With (?=babe) you only see them when they are in front of you, with (?=.*babe) you'll even see them when they are far away and with (?<=babe) you'll see them when they are directly behind you.
Lookbehinds are fixed width, meaning you can not use any quantifiers (+, ?, *, {m,n}). Lookarounds are also zero-width assertions, meaning they do not consume what they match.
Babewatching
With (?=babe) you only see them when they are in front of you, with (?=.*babe) you'll even see them when they are far away and with (?<=babe) you'll see them when they are directly behind you.
options:
i:
case insensitive
m:
make ^$ match start and end of line respectively
s:
make dot match newlines
g:
all matches
Note that this website uses PHPs implementation of PCRE! Read more here.