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

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages