I need to get string which are not attachments.
(Is not between <li></li>
)
Example:
i need this string!
<div>i need this string too!</div>
:)<li>I don't need this string!</li>:)
Result:
i need this string!
<div>i need this string too!</div>
:):)
I tried this:
^(?!<li>.*$).*(?<!<\/li>)
But the problem is that if there is text next to my string
<li>text</li>
For example a smiley:
:)<li>I don't need this string!</li>:)
then the pattern does not work and I don’t understand how to fix it. Can you correct me please?
CodePudding user response:
Use re.sub()
to remove the string you don't want, instead of trying to match everything else.
result = re.sub('<li>.*?</li>', '', text);