Need help in Regex to exactly match the term

I want to match exactly to loves and not to dloves or lovesd

The regex used

(?<=variable.*>.*)(?<![\[""])loves(?![\]""])(?=.*<\/variable)

Input samples:

<variable>[loves]loves</variable> - ignore the loves in bracket,  but highlight the loves outside it
<variable>loves</variable>
<variable>dloves</variable> - ignore
<variable> loves</variable>
<variable>lovesd</variable> - ignore
<variable class="loves">loves</variable>  - ignore the loves in within <variable class="loves">,  but highlight the loves outside it

Hi,

How about the following pattern?

(?<=variable.*>.*)(?<![\w\[""])loves(?![\w\]""])(?=.*<\/variable)

Regards,

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.