Tuesday, April 27, 2010

Re: [Rails] regular expression problem

Hi --
On Tue, 27 Apr 2010, Vladimir Rybas wrote:

> "Antigua and Barbuda (+1268)".scan(/\d+/).to_s
> => 1268
>
> "Antigua and Barbuda (+1268)".scan(/\(\+\d+\)/).to_s
> => (+1268)

There's a nice technique for quickly getting a substring from a
string using a subscript-style notation:

"Antigua and Barbuda (+1268)"[/\(\+\d+\)/] # "(+1268)"


David

--
David A. Black, Senior Developer, Cyrus Innovation Inc.

THE Ruby training with Black/Brown/McAnally
COMPLEAT Coming to Chicago area, June 18-19, 2010!
RUBYIST http://www.compleatrubyist.com

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate