Regex To Match Words That Start With A Specific Character

Category: Strings

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:

Rate This Regex
Sending
User Review
0 (0 votes)

Expression Flags

Flags Description
i Ignore case sensitive.
g Allows global search.
m Allows multiline search.