Last Match Pattern Occurrence

Hi Guys, I have a block of code :

    `<ol start="3">
     <li><strong> Who can take part?</strong></li>
     </ol>
     <ul>
 <li>Selected customers. Including (#amount=45GBP#). </li>
 </ul>
 <p>&nbsp;</p>
 <ol start="4">
 <li><strong> What else do I need to know? </strong></li>
<ol start="5">
<li><strong> Other boring but essential stuff:</strong></li>
</ol>     

What I need to do is replace all “<ol +” instances so all the <ol start=*'s

But i need to keep the first instance of (the first and last ones)

I was trying to use regex to find the last one with this: (</ol)(?!.*\1) but i still get 3 matches.

Could anyone provide any input/thoughts on how to go about removing all instances except the first and last one in the string?

Many Thanks!!

Hi @Kyleb91,

I think it is bit confusing, Kindly share the input and expected output, It will help us to understand better.

Warm Regards,
Ranjith Udayakumar

1 Like

Apologies.

<ol start="3">
     <li><strong> Who can take part?</strong></li>
     **</ol>**
     <ul>
 <li>Selected customers. Including (#amount=45GBP#). </li>
 </ul>
 <p>&nbsp;</p>
 **<ol start="4">**
 <li><strong> What else do I need to know? </strong></li>
**<ol start="5">**
<li><strong> Other boring but essential stuff:</strong></li>
</ol>     

The above is my string of text, and I wish to replace the highlighted (Everything between **) pieces/Delete them.

But I would like to keep the first and last instances of <ol*/

Hi @Kyleb91,

Please find the XAML file which i developed and tested for your scenario. Let me know if you have any concerns.

If you find it useful, Mark it as Solution.

HTMLText.txt (336 Bytes) outHTML.txt (301 Bytes) RegEx.xaml (7.5 KB)

Warm Regards,
Ranjith Udayakumar

1 Like

That is fantastic @ranjith_udayakumar thanks so much!

I see you called out the pattern of 3 separate groups and then call upon them, brilliant.

I am newish to RegEx, so is the Group(0) All, and then subsequent (1),(2),(3) are the separated groups?

1 Like

Hi @Kyleb91,

Thanks for your kind words, The Matches starts from the Index 0 and Grouping starts from the Index 1.

Hope it helps.

Warm Regards,
Ranjith Udayakumar

1 Like

Hi @ranjith_udayakumar - in a similar fashion to yesterday… "<table width="219">" is my string, I was hoping to group these like you did, I tried "(<table width="[0-9]+">)([0-9+])" but doesn’t work… I am trying to match the whole string with number, and then group just the number so I can extract/replace this.

Much appreciated!

Hi @Kyleb91,

As like before,Please share the input and output expected, it will easy to understand. I will share the regex and explanation. It will help you to overcome similar type of issues.

Thank you so much @ranjith_udayakumar.

There are 3 parts.

  1. Input: "<table width="219">" (This Number could be anything, so ‘x’, I would like to replace this number). So the replacement Output would be "<table border="1" width="0">"

  2. Input: <table style="width: 242px;"> (Again, this number be anything, so 243=x)
    Replacement Output: "<table border="1" width="0">"

  3. Input: <table style="width: 308px; height: 265px;"> (Numbers can be different).
    Replacement Output: "<table border="1" width="0">"

Much Appreciated!

Also @ranjith_udayakumar is there a way of replacing this text in the original strHTML file that you are inputting at the start, instead of creating a new file?

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