need to negate regex in middle of expression

S

Sherm Pendley

Thanks for the reply.

What reply? Please quote enough of the message you're replying to to provide
some context.
[not sure what i posted wrong outside the guideline?]

No idea what your original message was, or the reply you're apparently talking
about here, but the problem with this one is easy to see: You haven't quoted
any of the message you're replying to.

sherm--
 
E

ebillionaire

i need a regular expression that will allow me to search for the
following:
<a href="link">...</a> and replace them with <a href="link"
rel="abc">...</a>

however I want to skip the links that says <a href="mysite"> or <a
href="http://www.mysite"> or <a href="http://mysite"> for a few
different names in place of 'mysite'

so i am thinking i need a regex similar to the following:
s/(.*?<a href=")^(mysite|mysite2|mysite3)"(>.*?<\/a>).*?/$1$2"
rel="abc"$3/igms

but obviously the ^(mysite|mysite2|mysite3) will not work. I know you
can negate characters or strings at the beginning of an expression but
anyone knows how I can achieve the above?

thanks in advance.

nayeem
 
A

A. Sinan Unur

(e-mail address removed) wrote in @f14g2000cwb.googlegroups.com:
i need a regular expression that will allow me to search for the
following:
<a href="link">...</a> and replace them with <a href="link"
rel="abc">...</a>
....

anyone knows how I can achieve the above?

Go to <URL:http://search.cpan.org/>.

Look for modules related to parsing HTML.

Also, read perldoc -q html for why using a parser is easier.

While you are at it, please consult the posting guidelines for this group
as well.

Sinan
 
E

ebillionaire

Thanks for the reply. I know about the html parser modules but what i
am doing is quite simple, i think it will be an overkill, i am trying
to make a one-liner to search-replace as and when needed:

find ./ -name '*.*' | xargs perl -pi -e 's/.../../igms'
just finding the right RE will be enough to solve my problem.

cheers

nayeem
[not sure what i posted wrong outside the guideline?]
 
E

ebillionaire

ok got it now, needs to be done in 2 steps:
a) find ./ -name '*.*' | xargs perl -pi -e 's/(<a
href=".*?")(.*?)(>)/$1$2 rel="nofollow">/igms'
b) find ./ -name '*.*' | xargs perl -pi -e 's/(<a
href=".*?(domain1\.com|domain2\.com).*?")(.*?)(
rel="nofollow")>/$1$3>/igms'
 
J

Jürgen Exner

ok got it now, needs to be done in 2 steps:

What needs to be done in two steps. If you don't provide context then none
of your readers has any idea what problem you trying to tackle.

jue
 
A

A. Sinan Unur

(e-mail address removed) wrote in @g14g2000cwa.googlegroups.com:
ok got it now,

What did you get? Please quote enough context to make your messages
meaningful on their own.
needs to be done in 2 steps:
a) find ./ -name '*.*' | xargs perl -pi -e 's/(<a
href=".*?")(.*?)(>)/$1$2 rel="nofollow">/igms'
b) find ./ -name '*.*' | xargs perl -pi -e 's/(<a
href=".*?(domain1\.com|domain2\.com).*?")(.*?)(
rel="nofollow")>/$1$3>/igms'

Since I do not want to go digging for your original message, I have no
idea what the purpose of this code is, and therefore, I have no way of
checking what counter-examples might exist.

That would have been the value of quoting properly.

Sinan
 
A

A. Sinan Unur

(e-mail address removed) wrote in @g43g2000cwa.googlegroups.com:
Thanks for the reply.

Please quote some context in your replies.
I know about the html parser modules but what i
am doing is quite simple, i think it will be an overkill,

It is not overkill, it is very easy to write a simple handler to:
i am trying to make a one-liner to search-replace as and
when needed:

If a one liner is worth keeping around, then you might want to make a
proper script out of it
[not sure what i posted wrong outside the guideline?]

You did not supply a short but complete script along with proper sample
data to help us try various alternatives with ease. Without that
incentive, very few people will go out of their way to set up test
cases, explore potential pitfalls etc.

The guidelines are not rules for their own sake: Following them helps
you help yourself, and also enables you to help others help you.

Sinan
 
T

Tad McClellan

i need a regular expression that will allow me to search for the
following:
<a href="link">...</a> and replace them with <a href="link"
rel="abc">...</a>

however I want to skip the links that says <a href="mysite"> or <a
href="http://www.mysite"> or <a href="http://mysite"> for a few
different names in place of 'mysite'

anyone knows how I can achieve the above?


Match all of them, then add some checking logic in an s///e
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top