Regex matching for or sembol

You might for example use

\bt(?:[^\w\s]year)?\b
  • \b A word boundary to prevent a partial word match
  • t Match literally
  • (?:[^\w\s]year)? Optionally match a non word character except for a whitespace char
  • \b A word boundary

Regex demo

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top