n8o
n8o

Reputation: 1943

Regexp - match specific word allowing special characters

I wanna make a regular expression to find specific word allowing special characters(\W). For example, if the word is replace then:

It seems like I have to use (?=) operator, but I have no idea about how to use it.

Upvotes: 0

Views: 748

Answers (1)

anubhava
anubhava

Reputation: 785058

You may use this regex with word breaks and allowing any non-word, non-whitespace on either side:

[^\w\s]*\breplace\b[^\w\s]*

RegEx Demo

RegEx Details:

  • [^\w\s]0: Match optional 0+ non-word and non-whitespace character
  • \b: Word boundary
  • replace: match text replace
  • \b: Word boundary
  • [^\w\s]?: Match optional 0+ non-word and non-whitespace character

Upvotes: 1

Related Questions