Regular Expression replace question 
Author Message
 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  
 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  
 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  
 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  
 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  
 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  
 
 [ 6 post ] 

 Relevant Pages 

1. Regular Expression Replace Question

2. Regular Expression replace question

3. regular expression href replace question

4. Regular Expressions with Replace question...

5. regular expression href replace question

6. Search And Replace In IDE - Regular Expression

7. Replace Unicode using Regular Expressions

8. regular expressions with string.replace

9. Regular expressions to replace characters outside HTML tags

10. regular expression replace

11. VBScript - Regular Expressions replace

12. Replace HTML Tag value? (Regular Expression)

 

 
Powered by phpBB® Forum Software