# Regex group without capture

**URL:** <https://www.ruby-forum.com/t/regex-group-without-capture/86422>\
**Category:** Ruby\
**Created:** [February 22, 2007, 4:00am UTC](https://www.ruby-forum.com/t/regex-group-without-capture/86422 "2007-02-22T04:00:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [February 22, 2007, 4:00am UTC](https://www.ruby-forum.com/t/regex-group-without-capture/86422/1 "2007-02-22T04:00:25Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [February 22, 2007, 4:30am UTC](https://www.ruby-forum.com/t/regex-group-without-capture/86422/2 "2007-02-22T04:30:27Z")

</div>

From: S. Robert J. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] :

# 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
