Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   regexp warning in String.split? (http://www.velocityreviews.com/forums/t809587-regexp-warning-in-string-split.html)

Chris Morris 08-15-2003 01:02 PM

regexp warning in String.split?
 
irb(main):001:0> 'a,b'.split(',')
=> ["a", "b"]
irb(main):004:0> 'a => b'.split(' => ')
(irb):4: warning: string pattern instead of regexp; metacharacters
no longer eff
ective
=> ["a", "b"]

Why do I get a warning on the second split call?

--

Chris
http://clabs.org/blogki




Brian Candler 08-15-2003 01:09 PM

Re: regexp warning in String.split?
 
On Fri, Aug 15, 2003 at 10:02:10PM +0900, Chris Morris wrote:
> irb(main):001:0> 'a,b'.split(',')
> => ["a", "b"]
> irb(main):004:0> 'a => b'.split(' => ')
> (irb):4: warning: string pattern instead of regexp; metacharacters
> no longer eff
> ective
> => ["a", "b"]
>
> Why do I get a warning on the second split call?


Because you should be using:

'a => b'.split(/ => /)

(I don't think '=' or '>' by themselves has significance in a regexp, but in
combination they might do - if you use odd things like assertions)

Cheers,

Brian.



All times are GMT. The time now is 04:43 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.