View Full Version : Solved: Help Matching String Patterns

03-04-2009, 01:26 AM
I am trying to remove string patterns from a text file but having a little difficulty doing it efficiently. The file is HTML code and the pattern in the file is like:

"<a href=*******>"

i.e. it's a HTML tag.

The "*" represents some of the characters inside the tag.

The problem is, I don't know how many of these characters there will be.

I was hoping there would be an easy solution using Replace function. i.e. give it a string to match that equals the above pattern and replace it with "". Problem is, I don't know what the above would look like.

Any ideas?

Simon Lloyd
03-04-2009, 01:28 AM
I don't know how to use Regex (Regular Expressions) but thats probably what you need to look at for this.

03-04-2009, 01:29 AM
Yup, thought as much :)

I know very little about them also! Reading through this site at the moment:


03-04-2009, 01:29 AM
What are you trrying to remove, the tags or the other bit?

03-04-2009, 01:38 AM
This site will show you patterns to match a URL, assuming that it's the URL in the A HREF tag that you are trying to get at.


Can you pull the text file into excel, and if so where do the tags appear in the sheet?

03-04-2009, 05:21 AM
Thanks for the help guys. I found this function that does what I need:

Function Cleanup(arg As String) As String
Dim re As Object
Set re = CreateObject("VBScript.RegExp")
re.Global = True 'Takes out every instance when set to true
re.Pattern = "<a href[^>]*" 'Takes out everything between and including <a href.......>
Cleanup = re.Replace(arg, "")
End Function