Use word boundaries:
/\b($word)\b/i
Or if you’re searching for “S.P.E.C.T.R.E.” like in Sinan Ünür’s example:
/(?:\W|^)(\Q$word\E)(?:\W|$)/i
More Related Contents:
- What is a word boundary in regex?
- Oracle REGEXP_LIKE and word boundaries
- PostgreSQL Regex Word Boundaries?
- How to match the first word after an expression with regex?
- Reference – What does this regex mean?
- How does Stack Overflow generate its SEO-friendly URLs?
- How do I make part of a regex match optional?
- Regex Match all characters between two strings
- Regular expressions: Ensuring b doesn’t come between a and c
- What regular expression will match valid international phone numbers?
- Collapse and Capture a Repeating Pattern in a Single Regex Expression
- How to check that a string is a palindrome using regular expressions?
- Using alternation or character class for single character matching?
- Regex to find repeating numbers
- Use regular expression to match ANY Chinese character in utf-8 encoding
- How to ignore whitespace in a regular expression subject string?
- Regular Expression Lookbehind doesn’t work with quantifiers (‘+’ or ‘*’)
- Regular expression search replace in Sublime Text 2
- Phone validation regex
- Random Text generator based on regex [duplicate]
- Why are there so many different regular expression dialects?
- Split text by columns in PowerShell
- How to replace a whole line with sed?
- Unix grep regex containing ‘x’ but not containing ‘y’
- is there something akin to regEx in applescript, and if not, what’s the alternative?
- Replace newlines with literal \n
- Regex to match an ISO 8601 datetime string
- How to capture multiple regex matches, from a single line, into the $matches magic variable in Powershell?
- Javascript – regex – word boundary (\b) issue
- Extracting text after last period in string [duplicate]