Issue with regex

J

junkone1

I have a string
<A
HREF="http://stockcharts.com/h-sc/ui?s=ACN.TO&id=p41804099534&a=81626743&listNum=30">
<IMG SRC="/images/ico_candle_on.gif" BORDER=0 ALT="Default
SharpChart"></A><A HREF="/webcgi/wb.exe?gall.web+ACN.TO"><IMG
SRC="/images/ico_trendline_on.gif" BORDER=0 ALT="Gallery Page"></A><A
HREF="/def/servlet/SC.pnf?c=ACN.TO,P&listNum=30"><IMG
SRC="/images/ico_pnf_on.gif" BORDER=0 ALT="P&amp;F Chart"></A>




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
 
D

dblack

Hi --

I have a string
<A
HREF="http://stockcharts.com/h-sc/ui?s=ACN.TO&id=p41804099534&a=81626743&listNum=30">
<IMG SRC="/images/ico_candle_on.gif" BORDER=0 ALT="Default
SharpChart"></A><A HREF="/webcgi/wb.exe?gall.web+ACN.TO"><IMG
SRC="/images/ico_trendline_on.gif" BORDER=0 ALT="Gallery Page"></A><A
HREF="/def/servlet/SC.pnf?c=ACN.TO,P&listNum=30"><IMG
SRC="/images/ico_pnf_on.gif" BORDER=0 ALT="P&amp;F Chart"></A>




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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,686
Latest member
scamivo

Latest Threads

Top