0

So, I'm trying to edit a dictionary file with regex. My current regex can match the two closest strings (and everything between them). The problem is that I need to find only those strings that have a particular string between them. I tried to combine negative lookahead and positive lookahead, but without success.

Here's my current regex:

<b>(?:(?!<\/?b>).)*?<\/b>(?:(?!<\/?b>).)*?<font color=darkslategray>.*?<\/font>

An example with a small part of the dictionary file: https://regex101.com/r/yV1zC3/1

And I need to capture the closest occurrences of <b> </b> and <font color=darkslategray> </font> tags, but only if there are <VR> </VR> tags between them. The result should be:

<b>na·ive</b><br><div style="padding-left:0.5em;">(<VR><span style="color:#006400;font-style:italic">or</span>  <b>na·ïve</b></VR>) <font color=darkslategray>/nɑˈiːv, naıˈiːv/</font>
<b>na·ïve·té</b> (<VR><span style="color:#006400;font-style:italic">also</span>  <b>na·ive·te</b> <span style="color:#006400;font-style:italic">or</span>  <b>na·ive·té</b></VR>) <font color=darkslategray>/nɑˌiːvˈteı, naıˌiːvˈteı/</font>
<b>na·ive·ty</b> (<VR><span style="color:#006400;font-style:italic">also</span>  <b>na·ïve·ty</b></VR>) <font color=darkslategray>/nɑˈiːvəti, naıˈiːvəti/</font>

Is it even possible to do with regex?

Moreno
  • 21
  • 3
  • 5
    [don't parse html using regex](http://stackoverflow.com/a/1732454/633183) – Mulan Feb 18 '16 at 18:07
  • But you're not matching ` – bobble bubble Feb 18 '16 at 18:14
  • @bobble bubble, yes, in my example there's no mention of , because all my attempts to combine negative and positive lookahead have failed (although it seems that using positive lookahead was superfluous). So the example shows only the working part - matching the closest strings. I've had a look at your regex and it works as it should. Thank you! – Moreno Feb 18 '16 at 19:07

0 Answers0