Using Regex in a replace function? - Posted (889 Views)
Senior Member
bobby131313
Posts: 1163
1163
I've taught myself quite a bit using the replace function but now I'm stumped. I have a string I want to blank, but within the string is a string that changes randomly. Example....
lnk.Description = Replace(lnk.Description, "constantconstantchangesrandomlyconstantconstant", "")

The part in bold can vary in the number of characters also, can this be done using Regex... or something?
TIA!
 Sort direction, for dates DESC means newest first  
 Page size 
Posted
Support Moderator
Shaggy
Posts: 6780
6780
Code:
dim objRegex
set objRegex=new RegExp
objRegex.ignorecase=true
objRegex.global=true
objRegex.pattern="constant1(.+?)constant2"
lnk=objRegex.replace(lnk,"")
set objRegex=nothing
Search is your friend “I was having a mildly paranoid day, mostly due to the
fact that the mad priest lady from over the river had
taken to nailing weasels to my front door again.”
Posted
Senior Member
bobby131313
Posts: 1163
1163
Ooooooooooohhhh....... That's a beautiful thing... Thanks! bigsmile
Posted
Support Moderator
Shaggy
Posts: 6780
6780
You're welcome, Bobby smile
You can teach yourself regular expressions here and then use this for local testing.
Search is your friend “I was having a mildly paranoid day, mostly due to the
fact that the mad priest lady from over the river had
taken to nailing weasels to my front door again.”
Posted
Senior Member
bobby131313
Posts: 1163
1163
I've bookmarked them thanks!
Posted
Forum Moderator
AnonJr
Posts: 5768
5768
I saw this and immediately thought of this article... He's got a few other articles that round it out if you're in the reading mood.
 
You Must enter a message