Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: regex questions
e
1/27/2005 4:48:00 AM
> Lähettäjä: E S <eero.saynatkari@kolumbus.fi>
> Aihe: Re: regex questions
>
> > Lähettäjä: Jeff Davis <jdavis-list@empires.org>
> > Aihe: regex questions
> >
> > In python the regexes allow you to call a function instead of just
> > substitute the values (see <
http://docs.python.org/lib/node11...
for
> > more details). That seems quite useful, is there something similar in ruby?
> >
> > Also, let's say I want match anything between "a" and "b" unless it
> > contains the word "foo". I could write two regexes like so:
> >
> > if str =~ /a(.*)b/ and str !~ /a(.*foo.*)b/
> >
> > Is there a good way to make that kind of logic into one regex? Is there
> > some kind of "intersect" operator or a "not" operator?
>
> There's /(?!foo)/x, but I can't think of any proper way to get it to
> accept all other strings but the one specified. You could just
> invert your problem and reject any strings that *do* have a 'foo'
> between.
>
> unless str =~ /a.*?foo.*?b/
>
> If you need to, you can group to extract the non-foo part there.
That didn't come out right. What I meant to write is that if the above
match is not enough and you need to know that 'foo' is present, you
can simply do this:
str =~ /a.*?(foo).*?b/
fail if $1
> > Regards,
> > Jeff Davis
>
> E
>
>
>
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: regex questions
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password