From: dblack@...
Date: 2006-08-07T10:25:06+09:00
Subject: Re: Issue with regex
Hi --
On Mon, 7 Aug 2006, junkone1@gmail.com wrote:
> I have a string
> HREF="http://stockcharts.com/h-sc/ui?s=ACN.TO&id=p41804099534&a=81626743&listNum=30">
> 
SRC="/images/ico_trendline_on.gif" BORDER=0 ALT="Gallery Page"> HREF="/def/servlet/SC.pnf?c=ACN.TO,P&listNum=30">
SRC="/images/ico_pnf_on.gif" BORDER=0 ALT="P&F Chart">
>
>
>
>
> When i use the Regulator to create a regex it matches. my sample is
> "http(.)+["]
>
> It returns
> "http://stockcharts.com/h-sc/ui?s=ACN.TO&id=p41804099534&a=81626743&listNum=30">
>
> However when i use ruby, it returns
> When i use ruby with syntax a.scan(/"http(.)+["]/)
>
> It returns [["t"]]
>
> can someone help determine what error i am doing
When you use parenthetical captures, String#scan returns successive
arrays of those captures. In the case of your scan, you've matched
the string once, and captured "t" in the first () group.
If you want a substring that starts with "http and ends with ", you
can do:
a[/"http[^"]+"/]
David
--
http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <-----
http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log
http://www.manning.com/black => book, Ruby for Rails
http://www.rubycentral.org => Ruby Central, Inc.