Connecting Tech Pros Worldwide Forums | Help | Site Map

String matching

Newbie
 
Join Date: Aug 2008
Posts: 14
#1: Sep 4 '08
I've got a script which basically goes line by line through an external file, and hands it to the screen in a slightly parsed form.

I'd like to apply another bit of parsing to what's coming in though, and specifically look for a pattern matching "[[form=x]]" where x can be any number.

If that string is found, I'd like to grab the "x" part, pass it through a subroutine, and then replace the "[[" and "]]" and everything in between with a variable.

I think I can do the latter bit myself, it's just the matching the string (that is, any section of the line starting with "[[file=" and ending with "]]") and grabbing the number that I can't figure out.

Any help is much appreciated.

Newbie
 
Join Date: Aug 2008
Posts: 14
#2: Sep 5 '08

re: String matching


Update: I sorted this out myself using a regular expression. I suspected that would be the answer, but it was easier than I thought to get it working.

If anyone's interested, this is the code I used to grab the number in the [[form=]] tag:

Expand|Select|Wrap|Line Numbers
  1. Set oRegEx = New RegExp
  2.     With oRegEx
  3.         .Pattern = "\[\[form=.*?\]\]"
  4.         .IgnoreCase = True
  5.     End With
  6. Set temp = oRegEx.Execute(line)
  7. temp = Replace(temp(0),"[[form=","")
  8. temp = Replace(temp,"]]","")
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#3: Sep 5 '08

re: String matching


Thanks for posting the answer. I was about to answer that I could hard code it, but what you really need were regular expressions, and I had never used them in ASP. Glad we have that on file now :-)

Jared
Reply