Regex group without capture

S

S. Robert James

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)
 
P

Peña, Botp

From: S. Robert James [mailto:[email protected]] :
# 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top