# Regex group match

**URL:** <https://www.ruby-forum.com/t/regex-group-match/182585>\
**Category:** Ruby\
**Created:** [January 30, 2010, 12:30pm UTC](https://www.ruby-forum.com/t/regex-group-match/182585 "2010-01-30T12:30:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [January 30, 2010, 12:30pm UTC](https://www.ruby-forum.com/t/regex-group-match/182585/1 "2010-01-30T12:30:51Z")

</div>

At [www.rubular.com/](http://www.rubular.com/) the regular expression:

SID=([\s\S]_?)LSID=([\s\S]_?)Auth=([\s\S]\*)

run against the string below results in three captures. How do I  
replicate these results from Ruby? Part of the trick being that SID and  
LSID are similar, and presumably, may be returned in any order.

This comes from:

> **[Using cURL to interact with Google Data services  |  Google Data...](https://developers.google.com/gdata/articles/using_cURL?csw=1)**

clientlogin

thufir@ARRAKIS:~/projects/curl$  
thufir@ARRAKIS:~/projects/curl$ ruby regex.rb  
SID=  
thufir@ARRAKIS:~/projects/curl$  
thufir@ARRAKIS:~/projects/curl$ nl regex.rb

```
 1 # SID=([\s\S]*?)LSID=([\s\S]*?)Auth=([\s\S]*)
 2 # works at rubular to capture the three sub-strings

 3 s =

```

“SID=DQAAAHYBADCv2pSv7nflacDNwz3zEDUGtrSvNVDcpkSfddi77b3U5sEaHmP8YLWhmA36F9rk85mL8J5dqo4apn0T1vKz0fPGI9Xtnuet6cuE2ZzYvrNIwbSC\_HjTqF4zudNQnnlDuD2wqZT-  
g1qXI8KhGAQZV4NexHZoQPlabTsGuRZeIBxj1A  
4 LSID=EUBBBIaBADCl-kNxvRVmcQghpt3cqSMfEooKR9flLOUZqwgP9OrZS83gse-  
KSdTNeXhxsET7FYenDhceP9lIPOmesH-t9qh-AWUHjjMdZEbUNeF9mWyzln6Z-FajaiG-  
cVFkqW0ZJ8ZbnCP30xXj6xFK6QxaAcqy\_9Pej8jhEnxS9E61ftQGPg  
5 Auth=EUBBIacAAADK-kNxvRVmcQghpt3cqSMfEooLNMflLNIQqwgP9OrZS83gs-  
KSdTNeXhxsET7FYePWmaD8Vsy1V4LSUGMUP48Je2TO8OcjBj6HgAtPhiZeX-  
gKDfagZDK44j4n-Tkb44nhOnp2\_QPSnBj3Z2vYwOEDjjG3Q53aQVC2132JKOuGh”

```
 6 #s = "Here is a string with http://www.mydomain.com/path/to/

```

mypage.html in it"  
7 #r = /http://([a-z.]_)(/[a-z]_)_(/[a-z]_.html)/i  
8 #m = r.match s  
9 #p m.string

```
10 sid = /SID=[\s\S]*?/

11 puts sid.match s

```

thufir@ARRAKIS:~/projects/curl$

thanks,

Thufir

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [January 30, 2010, 1:14pm UTC](https://www.ruby-forum.com/t/regex-group-match/182585/2 "2010-01-30T13:14:10Z")

</div>

Solution:

thufir@ARRAKIS:~/projects/curl$  
thufir@ARRAKIS:~/projects/curl$ nl regex.rb

```
 1 # SID=([\s\S]*?)LSID=([\s\S]*?)Auth=([\s\S]*)
 2 # http://rubular.com/regexes/13295
 3 # 

```

> **[Using cURL to interact with Google Data services  |  Google Data...](https://developers.google.com/gdata/articles/using_cURL?csw=1)**

```
 4 str =

```

“SID=DQAAAHYBADCv2pSv7nflacDNwz3zEDUGtrSvNVDcpkSfddi77b3U5sEaHmP8YLWhmA36F9rk85mL8J5dqo4apn0T1vKz0fPGI9Xtnuet6cuE2ZzYvrNIwbSC\_HjTqF4zudNQnnlDuD2wqZT-  
g1qXI8KhGAQZV4NexHZoQPlabTsGuRZeIBxj1A  
5 LSID=EUBBBIaBADCl-kNxvRVmcQghpt3cqSMfEooKR9flLOUZqwgP9OrZS83gse-  
KSdTNeXhxsET7FYenDhceP9lIPOmesH-t9qh-AWUHjjMdZEbUNeF9mWyzln6Z-FajaiG-  
cVFkqW0ZJ8ZbnCP30xXj6xFK6QxaAcqy\_9Pej8jhEnxS9E61ftQGPg  
6 Auth=EUBBIacAAADK-kNxvRVmcQghpt3cqSMfEooLNMflLNIQqwgP9OrZS83gs-  
KSdTNeXhxsET7FYePWmaD8Vsy1V4LSUGMUP48Je2TO8OcjBj6HgAtPhiZeX-  
gKDfagZDK44j4n-Tkb44nhOnp2\_QPSnBj3Z2vYwOEDjjG3Q53aQVC2132JKOuGh”

```
 7 m = str.match(/SID=([\s\S]*?)LSID=([\s\S]*?)Auth=([\s\S]

```

\*)/).captures

```
 8 puts "SID\n" + m[0]
 9 3.times {puts " *********"}
10 puts "LSID\n" + m[1]
11 3.times {puts " *********"}
12 puts "Auth\n" + m[2]
13 3.times {puts " *********"}

```

thufir@ARRAKIS:~/projects/curl$

-Thufir
