-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
  • 7,734
  • 8
  • 55
  • 100

1 Answers1

3

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

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

Demo

Brad Solomon
  • 38,521
  • 31
  • 149
  • 235
emsimpson92
  • 1,779
  • 1
  • 9
  • 24