[Ruby] regex question

Ryan Davis ryand-ruby at zenspider.com
Tue Feb 13 01:39:48 PST 2007


On Feb 12, 2007, at 5:44 PM, shaners becker wrote:

> this worked. thanks so much. this is why i like this mailing list so
> much.

YAY!

>> Thats because the match was greedy.  Try this:
>>   <recommendations>(?m).*?</recommendations>
>
> this did not.
>
>> Or this:
>>   <recommendations>(?m)[^>]*</recommendations>
>
> regex are my next big project to wrap my head around.

Do note that "regex" (and variants) are a pretty generic thing. You  
can learn the basics and apply them pretty much anywhere (perl, sed,  
ruby, emacs, vim, subetha, textmate, etc) but unfortunately, each one  
is going to be slightly different from the next. The mechanics will  
be roughly the same, but there will be differences.

I personally like Mike's idea of experimenting in irb. I do it all  
the time. But I can also say that having an editor that provides you  
with live results can really speed up your learning/understanding of  
the patterns. Emacs has something called "regexp-builder" that can  
visually help you experiment until you find the right pattern.  There  
are also some good pages here:

	http://www.emacswiki.org/cgi-bin/wiki/CategoryRegexp

and not all of them are emacs specific.



More information about the Ruby mailing list