Regex To Match Words That Start With A Specific Character

A regular expression to match all words that start with a specific character (e.g. #, @, etc) in a string.

Note that don’t forget to replace the P in the regex with your own character.

/(?<!\w)P\w+/g

Matches:

  • Prefix
  • Pattern
  • Putty

Non-matches:

  • prefix
  • patternP
  • 12345

See Also:

Regex Is Copied!