Regular Expressions 101

@regex101
Donate
Sponsor
Contact
Bug Reports & Feedback
Wiki
Whats new?

Save & Share

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

Flavor

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

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
(?:(?<=^|[^\w0-9-_])(?<!@)@)([\w0-9-_])(?=[^\w@]|$)(?!@)
/
g
Non-capturing group
(?:(?<=^|[^\w0-9-_])(?<!@)@)
Positive Lookbehind
(?<=^|[^\w0-9-_])
Assert that the Regex below matches
1st Alternative
^
^ asserts position at start of the string
2nd Alternative
[^\w0-9-_]
Match a single character not present in the list below
[^\w0-9-_]
\w matches any word character (equivalent to [a-zA-Z0-9_])
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
- matches the character - literally (case sensitive)
This hyphen is treated literally, which might be confusing for others. Consider escaping it or placing at the start or end of the class!
_ matches the character _ literally (case sensitive)
Negative Lookbehind
(?<!@)
Assert that the Regex below does not match
@ matches the character @ literally (case sensitive)
@ matches the character @ literally (case sensitive)
1st Capturing Group
([\w0-9-_])
Match a single character present in the list below
[\w0-9-_]
* 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_])
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
- matches the character - literally (case sensitive)
This hyphen is treated literally, which might be confusing for others. Consider escaping it or placing at the start or end of the class!
_ matches the character _ literally (case sensitive)
Positive Lookahead
(?=[^\w@]|$)
Assert that the Regex below matches
1st Alternative
[^\w@]
Match a single character not present in the list below
[^\w@]
\w matches any word character (equivalent to [a-zA-Z0-9_])
@ matches the character @ literally (case sensitive)
2nd Alternative
$
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
Negative Lookahead
(?!@)
Assert that the Regex below does not match
@ matches the character @ literally (case sensitive)
Global pattern flags
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
g

Test String