[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

accessing all matches using regex

spike grobstein

8/6/2007 4:06:00 AM

Hey all

so, I primarily use PERL for creating shell scripts but I'm trying to
learn ruby since it feels like it could do more of what I want with
cleaner code. I especially like the way it has regex built right in.

I'm running into an issue though, because in perl, I can do this:

while (/href=\"([^\"]+)\"/) {
## do stuff...
}

I use this simple regex because it's based around what I use this style
for the most.

I can't figure out how to that in ruby. how can I iterate over all
matches in a string? I could split the lines, but sometimes there may be
two or more matches on a single line.

is there a nice, clean, ruby way to do this?

Thanks!
--
Posted via http://www.ruby-....

6 Answers

Jim Marshall

8/6/2007 4:31:00 AM

0

On 8/5/07, Spike Grobstein <spike666@mac.com> wrote:
> while (/href=\"([^\"]+)\"/) {
> ## do stuff...
> }
> ...
> I can't figure out how to that in ruby. how can I iterate over all
> matches in a string? I could split the lines, but sometimes there may be
> two or more matches on a single line.
>
> is there a nice, clean, ruby way to do this?
>

Have a look at String#scan ("ri String#scan" might do it, depending
upon your installation).
For example,
>some_string_with_html.scan(/href=\"([^\"]+)\"/) do |match|
> do_stuff_with match
>end

Gordon Thiesfeld

8/6/2007 4:33:00 AM

0

> is there a nice, clean, ruby way to do this?

Have a look at String#scan

spike grobstein

8/6/2007 12:24:00 PM

0

david karapetyan wrote:
> look up gsub! for the String class. you can write
>
> some_string.gsub(/href=\"([^\"]+)\"/) do |match|
> ## do stuff with match
> end
>
> i'm pretty sure the above code will work for what you are trying to do.

you know, I thought about String#scan, but for some reason didn't think
it was what I was looking for, but it works sorta nicely. it doesn't
behave exactly how I'd want... but the String#gsub method looks more
like what I'm looking for; this way, I can loop and access my various
$1, $2, etc matches and not have to work with an array that I have to
loop over in a weird way (since I don't use some of matches).

I'll have to play with this a little more.

thanks!
--
Posted via http://www.ruby-....

LibtardFilth

1/25/2011 3:15:00 AM

0


"J. Fartlington Poopnagel" <perryneheum@hotmail.com> wrote in message
news:ed095c9b-ff63-4a86-a3a9-85dacc7e4643@q8g2000prm.googlegroups.com...
> BUT, HYMIE -- OUR JOBLESS ARE NOT ROLLING IN EMPLOYMENT!
>
> WHAT GIVES?

What business in their right mind will hire people unless there's no
alternative. They don't want the unknown expenses associated with employees
until Obammy-care is repealed and/or changed and Cap-N-Tax is totally dead.
Until then, no jobs!


Lamont Cranston

1/25/2011 10:36:00 PM

0

On 1/24/2011 7:14 PM, LibtardFilth wrote:
> "J. Fartlington Poopnagel"<perryneheum@hotmail.com> wrote in message
> news:ed095c9b-ff63-4a86-a3a9-85dacc7e4643@q8g2000prm.googlegroups.com...
>> BUT, HYMIE -- OUR JOBLESS ARE NOT ROLLING IN EMPLOYMENT!
>>
>> WHAT GIVES?
>
> What business in their right mind will hire people unless there's no
> alternative. They don't want the unknown expenses associated with employees
> until Obammy-care is repealed

It won't be.

> and/or changed and Cap-N-Tax is totally dead.

That will never happen.

> Until then, no jobs!

Bullshit. There are plenty of jobs. American corporations created over
3 million jobs last year, most in foreign countries. Until the
Republican-sponsored legislation that rewards corporations for
outsourcing is repealed, there won't be any jobs in the US.

Buster Norris

1/26/2011 1:33:00 AM

0

On Mon, 24 Jan 2011 17:59:50 -0800 (PST), "J. Fartlington Poopnagel"
<perryneheum@hotmail.com> wrote:

Frauds are Exposed:

alt.politics IP Search Results File: C:\AP_Data\Q_76.100.8.74.txt
01/22/2011

This search result file generated by DemocRAT Hall Of Shame.Com
Copyright? 2010 DemocRAT Hall Of Shame.Com
---------------------------------------------------------------

AbortedBaby <jismquiff@yahoo.com>|76.100.8.74
Cheney sDick <kinkysr@yahoo.com>|76.100.8.74
CrabsForSale <lilhornie@yahoo.com>|76.100.8.74
David Weinstein <perryneheum@hotmail.com>|76.100.8.74
DrippingTwat <clitteigh@yahoo.com>|76.100.8.74
Elfin Tyusis <slipuvalad@yahoo.com>|76.100.8.74
J. Fartlington Poopnagel <perryneheum@hotmail.com>|76.100.8.74
John Fartlington Poopnagel <jismquiff@yahoo.com>|76.100.8.74
John Fartlington Snodnagel <perryneheum@hotmail.com>|76.100.8.74
Kyle Schwitters <slipuvalad@yahoo.com>|76.100.8.74
MissPuss <lilhornie@yahoo.com>|76.100.8.74
Nancing Prancer <perryneheum@hotmail.com>|76.100.8.74
Obwon Gandalf Hope IV <perryneheum@hotmail.com>|76.100.8.74
Old Grand Bag <jismquiff@yahoo.com>|76.100.8.74
Omar al Bashir <jismquiff@yahoo.com>|76.100.8.74
Palin sAbortion <kinkysr@yahoo.com>|76.100.8.74
Palin sHotHeinie <lilhornie@yahoo.com>|76.100.8.74
Palin sWormyAnus <lilhornie@yahoo.com>|76.100.8.74
PearlNecklace <clitteigh@yahoo.com>|76.100.8.74
Peeter <kinkysr@yahoo.com>|76.100.8.74
Perino sHeinie <perryneheum@hotmail.com>|76.100.8.74
PungentPussy <clitteigh@yahoo.com>|76.100.8.74
Richie Nearsen <slipuvalad@yahoo.com>|76.100.8.74
Rush sButtBoy <kinkysr@yahoo.com>|76.100.8.74
Scalia sButtBoy <perryneheum@hotmail.com>|76.100.8.74
Sigmond Fraud <slipuvalad@yahoo.com>|76.100.8.74
Slappy <kinkysr@yahoo.com>|76.100.8.74
Youwang Wang <kinkysr@yahoo.com>|76.100.8.74
slightly horny <lilhornie@yahoo.com>|76.100.8.74

Search start: Sat 1/22/2011 5:25:54 PM - End: Sat 1/22/2011 5:26:02 PM

---------------------------------------------------------------
Copyright? 2010 DemocRAT Hall Of Shame.Com

NNTP-Posting-Host: 76.100.8.74
Host: c-76-100-8-74.hsd1.va.comcast.net
14011-14099 Central Loop
Dale City, VA 22193

alt.politics IP Search Results File: C:\AP_Data\Q_69.255.48.21.txt
01/22/2011

This search result file generated by DemocRAT Hall Of Shame.Com
Copyright? 2010 DemocRAT Hall Of Shame.Com
---------------------------------------------------------------

David Weinstein <perryneheum@hotmail.com>|69.255.48.21
John Fartlington Poopnagel <jismquiff@yahoo.com>|69.255.48.21
John Fartlington Snodnagel <perryneheum@hotmail.com>|69.255.48.21
Palin sAbortion <kinkysr@yahoo.com>|69.255.48.21
Perry Neheum <perryneheum@hotmail.com>|69.255.48.21
jismquiff <jismquiff@yahoo.com>|69.255.48.21
littlebopper <jismquiff@yahoo.com>|69.255.48.21
spicpussy <clitteigh@yahoo.com>|69.255.48.21

Search start: Sat 1/22/2011 5:27:10 PM - End: Sat 1/22/2011 5:27:14 PM

---------------------------------------------------------------
Copyright? 2010 DemocRAT Hall Of Shame.Com

NNTP-Posting-Host: 69.255.48.21
Host: c-69-255-48-21.hsd1.va.comcast.net
15053 Blackburn Rd
Woodbridge, VA 22191

alt.politics IP Search Results File: C:\AP_Data\Q_69.140.253.235.txt
01/22/2011

This search result file generated by DemocRAT Hall Of Shame.Com
Copyright? 2010 DemocRAT Hall Of Shame.Com
---------------------------------------------------------------

Aknee Wombustre <clitteigh@yahoo.com>|69.140.253.235
BIGtits <clitteigh@yahoo.com>|69.140.253.235
BIGtitties <clitteigh@yahoo.com>|69.140.253.235
Ben Quayle <lilhornie@yahoo.com>|69.140.253.235
Bobo Cuccinelli <jismquiff@yahoo.com>|69.140.253.235
Butt sRushBoy <kinkysr@yahoo.com>|69.140.253.235
Christine O Donnell <kinkysr@yahoo.com>|69.140.253.235
Christine O Donnell <lilhornie@yahoo.com>|69.140.253.235
Contorted Aborted <kinkysr@yahoo.com>|69.140.253.235
CrabsForSale <lilhornie@yahoo.com>|69.140.253.235
DaffyDumbShit <jismquiff@yahoo.com>|69.140.253.235
Dan Quayle <lilhornie@yahoo.com>|69.140.253.235
David Weinstein <perryneheum@hotmail.com>|69.140.253.235
Fart Sumpter <jismquiff@yahoo.com>|69.140.253.235
Fenimore Cooper <slipuvalad@yahoo.com>|69.140.253.235
Goering sDaughter <kinkysr@yahoo.com>|69.140.253.235
Goering sGrandson <slipuvalad@yahoo.com>|69.140.253.235
HaitianHattie <lilhornie@yahoo.com>|69.140.253.235
J. Fartlington Poopnagel <perryneheum@hotmail.com>|69.140.253.235
Jimmy Carter <kinkysr@yahoo.com>|69.140.253.235
John F. Poopnagel <perryneheum@hotmail.com>|69.140.253.235
John Fartlington Poopnagel <jismquiff@yahoo.com>|69.140.253.235
John Fartlington Poopnagel <perryneheum@hotmail.com>|69.140.253.235
Julian Assange <lilhornie@yahoo.com>|69.140.253.235
Julie Assange <slipuvalad@yahoo.com>|69.140.253.235
Ken Cuccinelli <jismquiff@yahoo.com>|69.140.253.235
Kim Jong Eun <perryneheum@hotmail.com>|69.140.253.235
Kyle Schwitters <slipuvalad@yahoo.com>|69.140.253.235
MissPuss <lilhornie@yahoo.com>|69.140.253.235
Mr. Bluster <kinkysr@yahoo.com>|69.140.253.235
Nancing Prancer <perryneheum@hotmail.com>|69.140.253.235
Obwon Gandalf Hope IV <perryneheum@hotmail.com>|69.140.253.235
Old Grand Bag <jismquiff@yahoo.com>|69.140.253.235
Palin sAnusRimmer <perryneheum@hotmail.com>|69.140.253.235
Palin sButtBoy <perryneheum@hotmail.com>|69.140.253.235
Palin sHotHeinie <lilhornie@yahoo.com>|69.140.253.235
Palin sTwat <perryneheum@hotmail.com>|69.140.253.235
PearlNecklace <clitteigh@yahoo.com>|69.140.253.235
Richie Nearsen <slipuvalad@yahoo.com>|69.140.253.235
SalamiSam <perryneheum@hotmail.com>|69.140.253.235
Sarah \ DaffyDumbShit\ Palin <kinkysr@yahoo.com>|69.140.253.235
Scalia sButtBoy <perryneheum@hotmail.com>|69.140.253.235
Slappy <kinkysr@yahoo.com>|69.140.253.235
Sydney Limbaugh <slipuvalad@yahoo.com>|69.140.253.235
Unviable Tissue Mass <kinkysr@yahoo.com>|69.140.253.235
WellOiledBooty <lilhornie@yahoo.com>|69.140.253.235
Willow sAnusRimmer <perryneheum@hotmail.com>|69.140.253.235
Youwang Wang <kinkysr@yahoo.com>|69.140.253.235
\ DaffyDumbShit\ Palin <kinkysr@yahoo.com>|69.140.253.235
bigTITS <clitteigh@yahoo.com>|69.140.253.235
nicenips <clitteigh@yahoo.com>|69.140.253.235
suckTHESE <clitteigh@yahoo.com>|69.140.253.235

Search start: Sat 1/22/2011 5:28:20 PM - End: Sat 1/22/2011 5:28:34 PM

---------------------------------------------------------------
Copyright? 2010 DemocRAT Hall Of Shame.Com

NNTP-Posting-Host: 69.140.253.235
Host: c-69-140-253-235.hsd1.va.comcast.net
Woodbridge, VA
15053 Blackburn Rd
Woodbridge, VA 22191

Posted from:
The DemocRATs Hall of Shame!
http://www.democrathallof...