Regex To Match Anything Except Underscore

A regular expression matches anything before and after an underscore(_) in a string.

/[^_\W]+/

Matches:

  • regex_pattern
  • 123_456
  • abc_123_456

Non-matches:

  • regex-pattern
  • regex pattern
  • regexpattern

See Also: