Using Regex in a replace function? - Postet den (890 Views)
Senior Member
bobby131313
Innlegg: 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!
   
 Sidestørrelse 
Postet den
Support Moderator
Shaggy
Innlegg: 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.”
Postet den
Senior Member
bobby131313
Innlegg: 1163
1163
Ooooooooooohhhh....... That's a beautiful thing... Thanks! bigsmile
Postet den
Support Moderator
Shaggy
Innlegg: 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.”
Postet den
Senior Member
bobby131313
Innlegg: 1163
1163
I've bookmarked them thanks!
Postet den
Forum Moderator
AnonJr
Innlegg: 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.
 
Du må legge inn en melding