-2

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

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?

Alok
  • 6,361
  • 6
  • 43
  • 72

1 Answers1

3

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

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

Demo

Brad Solomon
  • 34,372
  • 28
  • 129
  • 206
emsimpson92
  • 1,771
  • 1
  • 7
  • 23