Issue in getting the correct regex

Hello Community,

I am facing the issue in regex.

I want the Word Fiber to be highlighted which are within opening and closing tags (>here<)

Sample Input:

<p>
<img src="../../../../Resources/Images/ZW (General)/ZW Fiber Closeup.png" class="Fiber" /> //Fiber within the tag shouldn't get highlighted
Fiber  //Just this Fiber to get highlighted
</p>

Sample input 2:

<h1>Fiber. dsdfsf</h1>  - Highlight Fiber
<h2>fdsfsd Fiber, </h1> - Highlight Fiber
<h3>dFiber</h3> - ignore -Fiber
<li> Fiber-Fiber - ignore this -Fiber
Fiber - - Highlight Fiber
Fiber. - Highlight Fiber
</li>
<li>Fiber </li> - Highlight Fiber
<li>My name is Fiber Vas</li> - Highlight Fiber
<variable class=" Fiber ">Fiberd</variable> - ignore Fiberd and ignore Fiber in class=" Fiber "
<h2 class="Fiber">Fiber</h2>- ignore  Fiber within class="Fiber" and - Highlight Fiber which is within  >< tags

The regex I use:

(?<=[>\s])Fiber(?=[\s\.\,<])

Thank you

Hi @hansen_Lobo

Use the below regular expressions to extract the required output

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,β€œ((?<=\>)\w{5}(?=\<))”)

Hope it helps!!

Doesnt Match some of the Fiber, in other statements

Can’t get you @hansen_Lobo

Could you explain me more

@hansen_Lobo

(?<=[>\s])Fiber(?=[\-\.\,<\/])|(?<=(\n|\>))Fiber(?=\s)|(?<=\s)Fiber(?=\s+[A-Z]+[a-z]+\<)

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,"(?<=[>\s])Fiber(?=[\-\.\,<\/])|(?<=(\n|\>))Fiber(?=\s)|(?<=\s)Fiber(?=\s+[A-Z]+[a-z]+\<)")

Hope it works!!

Hey @hansen_Lobo ,
The below regex satisfies your requirements
(?<=\"\>)\w+(?=\<)

So to explain this:
(?<=\"\>) => This will extract words after ">
\w+ => will extract all the words after that
((?=<) => This is like a limiter, it limits the text before < tag

If you are you using assign activity then refer below code
System.Text.RegularExpressions.Regex.Matches(YourinputString,"(?<=\"\>)\w+(?=\<)")

Hope it helps you!

Hey @hansen_Lobo ,
You can try
(?<=>|[\w+\s])Fiber(?!\s")(?=[\s\.,]|<)

Hi @hansen_Lobo

Try this

(?<=\>)(Fiber)(?=\b|\W|$)

I hope it helps!!

Hi @hansen_Lobo

Try this:

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,"(?<=[>\s])Fiber(?=[\-\s\.\,<])")

Hope it helps!!

@hansen_Lobo

(?<=[>\s])Fiber(?=[\-\.\,<\/])|(?<=(\n|\>))Fiber(?=\s)|(?<=\s)Fiber(?=\s+[A-Z]+[a-z]+\<)

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,"(?<=[>\s])Fiber(?=[\-\.\,<\/])|(?<=(\n|\>))Fiber(?=\s)|(?<=\s)Fiber(?=\s+[A-Z]+[a-z]+\<)")

Hope it works!!

last but one sample

<variable class=" Fiber ">Fiberd</variable>

The Class=" Fiber " highlighted

@hansen_Lobo

(?<=[>\s])Fiber(?=[\-\.\,<\/])|(?<=(\n|\>))Fiber(?=\s)|(?<=\s)Fiber(?=\s+[A-Z]+[a-z]+\<)

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,"(?<=[>\s])Fiber(?=[\-\.\,<\/])|(?<=(\n|\>))Fiber(?=\s)|(?<=\s)Fiber(?=\s+[A-Z]+[a-z]+\<)")

Hope it works!!

1 Like

Thank you works. If i come across any issue will get back to you.

@hansen_Lobo

Sure bro anytime

Happy Automation!!

1 Like

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