regexp warning in String.split?

Discussion in 'Ruby' started by Chris Morris, Aug 15, 2003.

  1. Chris Morris

    Chris Morris Guest

    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
    Chris Morris, Aug 15, 2003
    #1
    1. Advertising

  2. 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.
    Brian Candler, Aug 15, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carlos Ribeiro
    Replies:
    11
    Views:
    684
    Alex Martelli
    Sep 17, 2004
  2. Sam Kong
    Replies:
    5
    Views:
    221
    Rick DeNatale
    Aug 12, 2006
  3. haomiao
    Replies:
    1
    Views:
    163
    Tim Hunter
    Jul 26, 2007
  4. Joao Silva
    Replies:
    16
    Views:
    337
    7stud --
    Aug 21, 2009
  5. Stanley Xu
    Replies:
    2
    Views:
    582
    Stanley Xu
    Mar 23, 2011
Loading...

Share This Page