I read some posts here but they couldn’t help me figure out my issue:
you can read the below regexp which is trying to match the a place with excluding a specific string”Profile Pictures”.I wanted match all other cases if the beginning string of the expression is not “Profile Pictures”, but it doesn’t work:
re.compile(r"(?!Profile Pictures)</strong></a><div class=\"photoTextSubtitle fsm fwn fcg\">(\d+) photos</div>")
The matched numbers(\d+) are returned,but “Profile Pictures” is still counted as one of them.
I tried different ways but none of them works.However, I still feel negative lookahead is the way to solve it. Any ideas?
Thank you!
You’re using
(?!...or a negative lookahead assertion which according to the python regex documentationIn this case what you want is
(?<!...which is a negative lookbehind assertion. This is because you’re trying to avoid matching text that comes before the text you want to match, not after. From the regex docs:That’d give you a regex that looked like this instead:
Of course, it’s difficult to test this without some examples from you.