Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Match everything between two strings, including string

I feel I’m very close to what I’m trying to achieve but can’t quite get it right for VBScript

This expression works great for my use case but only with the ‘single line’ flag enabled which VBScript doesn’t seem to support:

<a\s* href="https:\/\/www.facebook.com\/TestCo\/">(.*?)&nbsp;</span>

I tried this to get around it but then I end up selecting too much of the text..

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<a\s* href="https:\/\/www.facebook.com\/TestCo\/">([\s\S]*)&nbsp;</span>

I’m trying to match and remove this line from the full text below:

<a href="https://www.facebook.com/TestCo/"><span
    style='font-size:14.0pt;font-family:"Times New Roman","serif";color:black;
    text-decoration:none;text-underline:none'><img border=0 width=19 height=19
    id="_x0000_i1026" src="Images/image002.png"></span></a><span
    style='font-size:14.0pt'>&nbsp;&nbsp;</span>

Here is the text I’m working with

    style='font-size:14.0pt;font-family:"Times New Roman","serif";color:black;
    text-decoration:none;text-underline:none'><img border=0 width=19 height=19
    id="_x0000_i1026" src="Images/image002.png"></span></a><span
    style='font-size:14.0pt'>&nbsp;&nbsp;</span><a
    href="https://www.linkedin.com/company/TestCo/"><span
    style='font-size:14.0pt;font-family:"Times New Roman","serif";color:black;
    text-decoration:none;text-underline:none'><img border=0 width=19 height=19
    id="_x0000_i1027" src="Images/image004.png"></span></a><span
    style='font-size:14.0pt'>&nbsp;&nbsp;</span><a
    href="https://twitter.com/TestCo"><span style='font-size:14.0pt;
    font-family:"Times New Roman","serif";color:black;text-decoration:none;
    text-underline:none'><img border=0 width=19 height=19 id="_x0000_i1028"
    src="Images/image006.png"></span></a><o:p></o:p></p>

Thank you

>Solution :

Dim regex: Set regex = New RegExp

regex.MultiLine = False
regex.Pattern = "<a\s* href=""https:\/\/www.facebook.com\/TestCo\/"">(.*?)&nbsp;</span>"
newString = regex.Replace(text, "")

Or if you want to match across multiple lines:

Dim regex: Set regex = New RegExp

regex.MultiLine = False
regex.Pattern = "<a\s* href=""https:\/\/www.facebook.com\/TestCo\/"">([\s\S]*?)&nbsp;</span>"
newString = regex.Replace(text, "")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading