Regular expression to match words which does not start with particular charector in python using negative lookahead assertion [duplicate]


Regular expression to match words which does not start with particular charector in python using negative lookahead assertion [duplicate]



This question already has an answer here:



In the string


s = 'Makeupby Antonia #makeup #makeupartist #makeupdolls #abhcosmetics'



I want to match only word which does not start with #. Means I want to select only Makeupby and Antonia
I tried using negative lookahead assertion


#


Makeupby


Antonia


re.findall(r'b(?![#])[a-zA-Z]+',s)

['Makeupby',
'Antonia',
'makeup',
'makeupartist',
'makeupdolls',
'abhcosmetics']



But this is matching with all words. Where I am wrong?



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




1 Answer
1



(?!) is syntax for a negative lookahead. You want a negative lookbehind.


(?!)



try b(?<!#)[a-zA-Z]+


b(?<!#)[a-zA-Z]+



Demo

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?