regular expression help

kdua
Posts: 10
Joined: Mon Jul 23, 2001 3:01 pm

regular expression help

Post by kdua »

i am trying to do the following:
i have a variable
$Url="www.tjsfasthealth.com/topsites/hiv_aids.php"
tjsfasthealth is not constant...it can be ptufasthealth or anything(but will be all alphabets).
i want to replace it with
www.fasthealth.com/topsites/hiv_aids.php
I am doing this
<sandr "\space*www\.[\alnum]+\.com" "www.fasthealth.com" $Url>
But it doesn't seem to work...can u help..
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

regular expression help

Post by Kai »

Remember that repetition operators in REX operate on the *entire* subexpression, not just the last character like Unix grep: you need an equals sign after the www.. Also, the expression should be anchored to the start of the string in case "www" occurs later in the path (unlikely, but possibly in a query string...):

<sandr ">>=\space*www\.=[\alnum]+\.com" "www.fasthealth.com" $Url>
User avatar
John
Site Admin
Posts: 2623
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH

regular expression help

Post by John »

There are a couple things you are missing. One is that the repetition applies to the longest preceding subexpression, so you need an "=" if you want one occurrence, and you need to reassign from $ret, so:

<sandr ">>=\space*www\.=[\alnum]+\.com=" "www.fasthealth.com" $Url>
<$Url=$ret>

should do the job. The >>= anchors it to the beginning of the buffer.
John Turnbull
Thunderstone Software