[Ruby] regex question
Daevid Vincent
daevid at daevid.com
Mon Feb 12 17:37:53 PST 2007
As previously mentioned, regex (by nature) are greedy. You can't just use a
.* as it will match ALL it can. You need a .*?
DÆVID
> -----Original Message-----
> From: ruby-bounces at zenspider.com
> [mailto:ruby-bounces at zenspider.com] On Behalf Of shaners becker
> Sent: Monday, February 12, 2007 5:31 PM
> To: Seattle Ruby Brigade!
> Subject: Re: [Ruby] regex question
>
> closer.
>
> that found a result. but only one result. it found from the first
> <recommendation> all the way through the last </recommendation>
> ignoring all the rest along the way
>
> the document is structured like so:
>
> book --1
> recommendation --1
> book --1a
> book --1b
> book --1c
> /recommendation --1
> /book --1
> book --2
> recommendation --2
> book --2a
> book --2b
> book --2c
> /recommendation --2
> /book --2
>
> and so on.
>
> > <recommendations>(?m).*</recommendations>
>
> finds from recommendation --1 all the way to /recommendation --2
> leaving only one book with no recommendations. instead of two books
> with no recommendations.
>
> -sb
>
>
> On Feb 12, 2007, at 5:16 PM, Frederick Alger wrote:
>
> >> I'm not sure how you'd do that in textmate....
> >
> > According to the TextMate manual, you can add a multiline
> flag to the
> > regex as so:
> >
> > <recommendations>(?m).*</recommendations>
> >
> > - Fred.
> > _______________________________________________
> > Ruby at zenspider.com - Seattle.rb non-commercial list
> > http://www.zenspider.com/seattle.rb
> > http://www.zenspider.com/mailman/listinfo/ruby
>
>
>
>
> -----------
> join the resistance. fall in love.
> http://theresistancearmy.com/
>
>
> _______________________________________________
> Ruby at zenspider.com - Seattle.rb non-commercial list
> http://www.zenspider.com/seattle.rb
> http://www.zenspider.com/mailman/listinfo/ruby
>
More information about the Ruby
mailing list