Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: regex questions
e
1/27/2005 4:38:00 AM
> 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.
> 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