Regular Expression replace question
Author |
Message |
Marcus Bel #1 / 6
|
 Regular Expression replace question
I am trying to scan a string to see if it contains an email adress. If it does, I want to convert it to an html tag with the "mailto:" anchor tag.
that the string would contain, then the following code works fine:
set oRegExp= new RegExp
RegExp.global=true str=oRegExp.replace(str,"<a href = mailto:$1>$1</a>") HOWEVER, the input string in my case may already be converted to the format
do NOT want a replace to take place. If I run the regexp replace on this, it will match the email address that is within the html tags, resulting in
match an email that it finds with, say, a ":" in front of it??
just not include the ":" in the match, but still match the rest of the email. Any ideas? Thanks in advance for any feedback! Marcus -- ---------------------------------------------------------------- To Reply, please remove "REMOVETHIS" from my email address ----------------------------------------------------------------
|
Mon, 10 Feb 2003 03:00:00 GMT |
|
 |
Walter Zacker #2 / 6
|
 Regular Expression replace question
Off the top of my head, I think that this will do it.
: I am trying to scan a string to see if it contains an email adress. If it : does, I want to convert it to an html tag with the "mailto:" anchor tag.
all : that the string would contain, then the following code works fine: :
kjhsjdkfhksjhfskdjfh " : set oRegExp= new RegExp
address of
: RegExp.global=true : str=oRegExp.replace(str,"<a href = mailto:$1>$1</a>") : : : HOWEVER, the input string in my case may already be converted to the format
which case I : do NOT want a replace to take place. If I run the regexp replace on this, : it will match the email address that is within the html tags, resulting in
to NOT : match an email that it finds with, say, a ":" in front of it?? :
it will : just not include the ":" in the match, but still match the rest of the : email. Any ideas? : : Thanks in advance for any feedback! : : Marcus : : : -- : ---------------------------------------------------------------- : To Reply, please remove "REMOVETHIS" from my email address : ---------------------------------------------------------------- : :
|
Mon, 10 Feb 2003 03:00:00 GMT |
|
 |
Marcus Bel #3 / 6
|
 Regular Expression replace question
Unfortunately this doesn't work. It still finds a match on the email address, but just doesn't match the beginning "<", so the replace would still replace where I do not want it to. Hmmm.... -- ---------------------------------------------------------------- To Reply, please remove "REMOVETHIS" from my email address ---------------------------------------------------------------- Quote:
> Off the top of my head, I think that this will do it.
> : I am trying to scan a string to see if it contains an email adress. > If it > : does, I want to convert it to an html tag with the "mailto:" anchor > tag.
> all > : that the string would contain, then the following code works fine: > :
> kjhsjdkfhksjhfskdjfh " > : set oRegExp= new RegExp
> address of
> : RegExp.global=true > : str=oRegExp.replace(str,"<a href = mailto:$1>$1</a>") > : > : > : HOWEVER, the input string in my case may already be converted to the > format
> which case I > : do NOT want a replace to take place. If I run the regexp replace on > this, > : it will match the email address that is within the html tags, > resulting in
> to NOT > : match an email that it finds with, say, a ":" in front of it?? > :
> it will > : just not include the ":" in the match, but still match the rest of > the > : email. Any ideas? > : > : Thanks in advance for any feedback! > : > : Marcus > : > : > : -- > : ---------------------------------------------------------------- > : To Reply, please remove "REMOVETHIS" from my email address > : ---------------------------------------------------------------- > : > :
|
Mon, 10 Feb 2003 03:00:00 GMT |
|
 |
Walter Zacker #4 / 6
|
 Regular Expression replace question
Using the above, the replace subexpression becomes $2 instead of $1.
: : Unfortunately this doesn't work. It still finds a match on the email : address, but just doesn't match the beginning "<", so the replace would : still replace where I do not want it to. Hmmm.... : : -- : ---------------------------------------------------------------- : To Reply, please remove "REMOVETHIS" from my email address : ----------------------------------------------------------------
: : > Off the top of my head, I think that this will do it. : >
: :
: > : I am trying to scan a string to see if it contains an email adress. : > If it : > : does, I want to convert it to an html tag with the "mailto:" anchor : > tag.
were : > all : > : that the string would contain, then the following code works fine: : > :
: > kjhsjdkfhksjhfskdjfh " : > : set oRegExp= new RegExp
: > address of
: > : RegExp.global=true : > : str=oRegExp.replace(str,"<a href = mailto:$1>$1</a>") : > : : > : : > : HOWEVER, the input string in my case may already be converted to the : > format
: > which case I : > : do NOT want a replace to take place. If I run the regexp replace on : > this, : > : it will match the email address that is within the html tags, : > resulting in
regexp : > to NOT : > : match an email that it finds with, say, a ":" in front of it?? : > :
because : > it will : > : just not include the ":" in the match, but still match the rest of : > the : > : email. Any ideas? : > : : > : Thanks in advance for any feedback! : > : : > : Marcus : > : : > : : > : -- : > : ---------------------------------------------------------------- : > : To Reply, please remove "REMOVETHIS" from my email address : > : ---------------------------------------------------------------- : > : : > : : > : > : :
|
Mon, 10 Feb 2003 03:00:00 GMT |
|
 |
Marcus Bel #5 / 6
|
 Regular Expression replace question
This still doesn't do it. This one only matches the pure pattern itself, i.e. it doesn't exclude certain patterns and match others depending on what precedes it. Marcus -- ---------------------------------------------------------------- To Reply, please remove "REMOVETHIS" from my email address ----------------------------------------------------------------
Quote:
> Using the above, the replace subexpression becomes $2 instead of $1.
> : > : Unfortunately this doesn't work. It still finds a match on the > email > : address, but just doesn't match the beginning "<", so the replace > would > : still replace where I do not want it to. Hmmm.... > : > : -- > : ---------------------------------------------------------------- > : To Reply, please remove "REMOVETHIS" from my email address > : ----------------------------------------------------------------
> : > : > Off the top of my head, I think that this will do it. > : >
> : > :
> : > : I am trying to scan a string to see if it contains an email > adress. > : > If it > : > : does, I want to convert it to an html tag with the "mailto:" > anchor > : > tag.
> were > : > all > : > : that the string would contain, then the following code works > fine: > : > :
> : > kjhsjdkfhksjhfskdjfh " > : > : set oRegExp= new RegExp
> : > address of
> : > : RegExp.global=true > : > : str=oRegExp.replace(str,"<a href = mailto:$1>$1</a>") > : > : > : > : > : > : HOWEVER, the input string in my case may already be converted to > the > : > format
> : > which case I > : > : do NOT want a replace to take place. If I run the regexp > replace on > : > this, > : > : it will match the email address that is within the html tags, > : > resulting in
> regexp > : > to NOT > : > : match an email that it finds with, say, a ":" in front of it?? > : > :
> because > : > it will > : > : just not include the ":" in the match, but still match the rest > of > : > the > : > : email. Any ideas? > : > : > : > : Thanks in advance for any feedback! > : > : > : > : Marcus > : > : > : > : > : > : -- > : > : ---------------------------------------------------------------- > : > : To Reply, please remove "REMOVETHIS" from my email address > : > : ---------------------------------------------------------------- > : > : > : > : > : > > : > > : > :
|
Tue, 11 Feb 2003 03:00:00 GMT |
|
 |
Richard Curzo #6 / 6
|
 Regular Expression replace question
Why not just detect if the mailto: is there, and then do your parsing only if necessary? RegExp's are wonderfully terse... but sometimes IMO it's a good idea NOT to do too much in one shot. Better to keep such high level issues visible in the code, and think of it as bonus to keep your regular expression more simple and readable. The more it different things it tries to do, the more trouble somebody is going to have changing it later! Of course there's another rule, "if it was hard to do it ought to be hard to change". <g> regards Richard.
Quote: > I am trying to scan a string to see if it contains an email adress. If it > does, I want to convert it to an html tag with the "mailto:" anchor tag.
> that the string would contain, then the following code works fine:
> set oRegExp= new RegExp
of
> RegExp.global=true > str=oRegExp.replace(str,"<a href = mailto:$1>$1</a>") > HOWEVER, the input string in my case may already be converted to the format
I > do NOT want a replace to take place. If I run the regexp replace on this, > it will match the email address that is within the html tags, resulting in
NOT > match an email that it finds with, say, a ":" in front of it??
will > just not include the ":" in the match, but still match the rest of the > email. Any ideas? > Thanks in advance for any feedback! > Marcus > -- > ---------------------------------------------------------------- > To Reply, please remove "REMOVETHIS" from my email address > ----------------------------------------------------------------
|
Thu, 13 Feb 2003 03:00:00 GMT |
|
|
|