I'm trying to use regex to see if there's a word with a string that contains '*'
and '*'
can't be either the start of the word or in the middle of the word;
For example:
ip* -> match
ip*5p -> not match
*ip -> not match
this is ip* -> match
give me *ip not here -> not match
I tried the expression:
p = r'(?!\*).*\b\*'
But it failed in the case of "ip*5p", it thinks it as a match.
But if I add "end of word" which is '\b'
p = r'(?!\*).*\b\*\b'
It failed in all the cases as find nothing.
Also, I tried
p = r'(?!\*)\b.*\*'
But still not working properly. Any hint?
Note: Strings must have exactly one *
symbol.
You could use the below regex which uses positive lookahead assertion.
OR
DEMO
\*(?=\s|$)
POsitive lookahead asserts that the character following the symbol*
must be a space character or end of the line anchor$
.