Need help in Regex to exactly match the term in html text

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

The regex used

(?<=>.*)loves(?=.*<)

Input samples:

<h1>loves</h1> -highlight loves
<h2> loves </h1> -highlight loves
<h3>dloves</h3> - ignore
<li> loves</li> -highlight loves
<li>loves </li> -highlight loves
<variable>lovesd</variable> - ignore lovesd
<h2 class="loves">loves</h2>  - ignore the loves in within <h2 class="loves">,  but highlight the loves outside it

try this \bloves\b(?!")

Hi @hansen_Lobo

To match the exact word “loves” and exclude cases like “dloves” or “lovesd” can you try:

(?<=^|[^a-zA-Z0-9_\-])loves(?=[^a-zA-Z0-9_\-]|$)

Best regards
Roman

Hi,

How about the following?

image

 System.Text.RegularExpressions.Regex.Matches(yourString,"(?<![\w""])loves(?![\w""])")

Regards,

@hansen_Lobo

[^""]\bloves\b[^""]

cheers

Why are you trying to parse the HTML instead of opening the web page in a browser and using activities to get the data you want?

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