Regex group without capture

Discussion in 'Ruby' started by S. Robert James, Feb 22, 2007.

  1. Is there a way to make a regex group without capturing the group (in
    Perl I believe it's possible, can't find any docs how to do this in
    Ruby)
     
    S. Robert James, Feb 22, 2007
    #1
    1. Advertising

  2. S. Robert James

    Peña, Botp Guest

    From: S. Robert James [mailto:] :
    # Is there a way to make a regex group without capturing the group (in
    # Perl I believe it's possible, can't find any docs how to do this in
    # Ruby)

    same, preprend "?:" , like (?:<expr_here>), where <expr_here> will not =
    be captured

    irb(main):006:0> "this is a test".scan /(this).*(test)/
    =3D> [["this", "test"]]
    irb(main):007:0> "this is a test".scan /(this).*(?:test)/
    =3D> [["this"]]
    irb(main):008:0> "this is a test".scan /(?:this).*(test)/
    =3D> [["test"]]

    kind regards -botp
     
    Peña, Botp, Feb 22, 2007
    #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. Max
    Replies:
    7
    Views:
    9,171
  2. Replies:
    3
    Views:
    1,589
  3. Replies:
    3
    Views:
    809
    Reedick, Andrew
    Jul 1, 2008
  4. christopher taylor
    Replies:
    0
    Views:
    430
    christopher taylor
    Sep 17, 2008
  5. RolfK
    Replies:
    1
    Views:
    1,907
    Martin Honnen
    Jun 7, 2009
Loading...

Share This Page