[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

regexp avoiding applying 2 times & -> &

pere.noel

1/26/2006 7:24:00 PM

i want to find a regexp avoiding to apply two times a entity transform
for the cases :

' or '
&
>
<
"

i found a way :

txtout=txtin.gsub(/&[^#aglq]/, "&")

which works, by chance, over the cases i have ))

the prob comes because the negate symbol ^ applies to the list of chars,
each individualy, following it. Then if i have a string including &a
(with my regex) the & will not be transformed to &, which is
wrong...

i'd like to know a way to say :

match & not followed by :
#\d\d;
amp;
gt;
lt;
quot;

i think this is only possible using back reference, that's to say ;
after having matched amp; (for example) negate the previous matching of
&...

but i don't know how to do that ))
--
une bévue
2 Answers

Ross Bamford

1/26/2006 7:31:00 PM

0

On Thu, 26 Jan 2006 19:23:35 -0000, "Une bévue"
<pere.noel@laponie.com.invalid> wrote:

> match & not followed by :
> #\d\d;
> amp;
> gt;
> lt;
> quot;
>

Does this work?

rxp = /&(?!(#\d\d|amp|quot|lt|gt);)/

"&amp;" =~ rxp
# => nil
"&#33;" =~ rxp
# => nil
"&lt;" =~ rxp
# => nil

"&" =~ rxp
# => 0
"&#33d;" =~ rxp
# => 0
"&how!" =~ rxp
# => 0
"&quo" =~ rxp
# => 0

Hope that helps,

--
Ross Bamford - rosco@roscopeco.remove.co.uk

pere.noel

1/26/2006 10:54:00 PM

0

Ross Bamford <rosco@roscopeco.remove.co.uk> wrote:

> Does this work?

yes !!! fine thanks !
--
une bévue