I need match next cases:
no word\ on your
no word\on your
no word\
no word
ignoring :
no word on your
My regular expression doesn't cover my needs
^.*(?=\bword\b)(?:\\.*|)$
To verify results you can use prepared configuration.
...Looking for help.
CodePudding user response:
Your positive lookahead is followed with \\.*
optional pattern followed with end of string, so the word
string should either start at the same location as \
does or at the end of string, which means, your regex will never match any text.
You can use
^.*\bword(?:\\.*)?$
See the regex demo. There is no need adding another \b
as \
after word
is already a non-word char, and if the optional \\.*
pattern does not exist, the end of string is already acting as a trailing word boundary for word
.
Details:
^
- start of string.*
- zero or more chars other than line break chars as many as possible\b
- a word boundaryword
- aword
(?:\\.*)?
- an optional non-capturing group matching\
and then any zero or more chars other than line break chars as many as possible$
- end of string.