Perl Regular Expression Help

SpomaMewor

Member
May 31, 2002
71
0
0
I am trying to do a search and replace in a cgi file. I need to search for all href= except those that have a mailto. So

Search for
href="
except if href="mailto

I want to do this in a regular expression. I could do it with some if statements but I figure regular expression will jsut be quicker.

I tried

s/href="?[^m]/$replace

but this does not seem to work. for some reason the href="mailto still matches.

any ideas.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Try this:
href="[^m]+

edit: this will still give you problems though, because it will match & replace the 'href="' along with the first character inside the href quotes. Which is probably not what you want
 

SpomaMewor

Member
May 31, 2002
71
0
0
that did not seem to do the trick. I am not sure what that matched because it severely screwed up the cgi page. A lot of other things seemed to have matched this.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Hmm ... it works in my regex explorer app.
It matches href=" plus the next character as long as that character is not an 'm'
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
You can't just assume that every line containing 'href="m' is going to be a line that contains 'href="mailto'. You will often come across links like: 'href="marketing.html"' and you don't want to replace those.

You're alot better off with something like this:

Note that this code doesn't work with single quoted href arguments like: href='mailto:you@me.com', only double quotes.