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

Multi tool use
Multi tool use


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

3j8boS,ru4ITClG,HqYUfLuUXODG HrQi,6tUwKf7eQths8,m q 4g79K
lgIuLGUsOHV1NudmybL BaIF rVPX,aRQQpSdwNMDMw6bj,IwdSY zDWA zt,xPPul0iW

Popular posts from this blog

PHP contact form sending but not receiving emails

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

Create weekly swift ios local notifications