[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Regex group without capture

S. Robert James

2/22/2007 2:58:00 AM

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)

1 Answer

Peña, Botp

2/22/2007 3:30:00 AM

0

From: S. Robert James [mailto:srobertjames@gmail.com] :
# 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)/
=> [["this", "test"]]
irb(main):007:0> "this is a test".scan /(this).*(?:test)/
=> [["this"]]
irb(main):008:0> "this is a test".scan /(?:this).*(test)/
=> [["test"]]

kind regards -botp