Reputation: 13
I am trying to extract a substring from a fragment of HTML code like this:
some text here. some text here.<img src="//zhihu.com/equation?tex=m_%7Bt%2B1%7D" alt="m_{t+1}" eeimg="1">some text here.<img src="//zhihu.com/equation?tex=p_t%3DE_t%28m_%7Bt%2B1%7Dx_%7Bt%2B1%7D%29" alt="p_t=E_t(m_{t+1}x_{t+1})" eeimg="1">some text here.
To draw substring m_{t+1}
contained in the first img
tag and p_t=E_t(m_{t+1}x_{t+1})
in the second tag, I just use a regexp <img.+ alt="((?!eeimg).)*" eeimg="1">
in Notepad++, but the expression does not match the the two img
tags seperately, it just shows a result which contains the whole HTML fragment.
Can anyone show me a correct way?
Thanks.
Upvotes: 1
Views: 468
Reputation: 762
You can make .+ non-greedy adding ? to it like this:
(<img(.+?) alt="((?!eeimg).)*" eeimg="1">)
Hope it helps you
Upvotes: 1