T
Thufir
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
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
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
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