Regex group match

At 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:

http://code.google.com/apis/gdata/articles/using_cURL.html#authenticating-
clientlogin

[email protected]:~/projects/curl$
[email protected]RAKIS:~/projects/curl$ ruby regex.rb
SID=
[email protected]:~/projects/curl$
[email protected]:~/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

[email protected]:~/projects/curl$

thanks,

Thufir

Solution:

[email protected]:~/projects/curl$
[email protected]:~/projects/curl$ nl regex.rb

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

http://code.google.com/apis/gdata/articles/using_cURL.html#authenticating-clientlogin

 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 "*********"}

[email protected]:~/projects/curl$

-Thufir

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs