[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

regex help

Its Me

4/27/2006 3:17:00 AM

I know I really should be able to do this but my best effort is quite
awkward. What is a simple regex way to find and extract the string
"abc/def.x.y" from the following:

.... stuff <img alt="???" src="abc/def.x.y" /> ...other stuff

I can assume <img..../> is all on one line.

Thanks.


6 Answers

Jeff Schwab

4/27/2006 4:19:00 AM

0

itsme213 wrote:
> I know I really should be able to do this but my best effort is quite
> awkward. What is a simple regex way to find and extract the string
> "abc/def.x.y" from the following:
>
> .... stuff <img alt="???" src="abc/def.x.y" /> ...other stuff

irb(main):001:0> s = '... stuff <img alt="???" src="abc/def.x.y" />
....other stuff'
=> "... stuff <img alt=\"???\" src=\"abc/def.x.y\" /> ...other stuff"
irb(main):002:0> s =~ /src="(.*?)"/
=> 25
irb(main):003:0> print $1
abc/def.x.y=> nil
irb(main):004:0>

speedy73

4/27/2006 9:01:00 AM

0

Jeffrey Schwab a écrit :
> itsme213 wrote:
>> I know I really should be able to do this but my best effort is quite
>> awkward. What is a simple regex way to find and extract the string
>> "abc/def.x.y" from the following:
>>
>> .... stuff <img alt="???" src="abc/def.x.y" /> ...other stuff
>
> irb(main):001:0> s = '... stuff <img alt="???" src="abc/def.x.y" />
> ...other stuff'
> => "... stuff <img alt=\"???\" src=\"abc/def.x.y\" /> ...other stuff"
> irb(main):002:0> s =~ /src="(.*?)"/
> => 25
> irb(main):003:0> print $1
> abc/def.x.y=> nil
> irb(main):004:0>
Yes and after:
----------------- test.rb ---------------------------
#!/usr/bin/env ruby

s = '... stuff <img alt="???" src="abc/def.x.y" /> ...other stuff'
r = regexp.new(/src="(.*?)"/)
if res = r.match(ligne)
print res[0], "\n"
print res[1]
end
-----------------------------------------------------

Where res[0] is the all match and res[1] is what you want the thing in
the group delimited by ()

uncutstone

4/27/2006 9:03:00 AM

0

s = "<img alt=\"???\" src=\"abc/def.x.y\" /> "
puts s
puts ( /<img.*src="(.*)" \/>/).match(s)[1]

result:
<img alt="???" src="abc/def.x.y" />
abc/def.x.y

William James

4/28/2006 6:51:00 AM

0


itsme213 wrote:
> I know I really should be able to do this but my best effort is quite
> awkward. What is a simple regex way to find and extract the string
> "abc/def.x.y" from the following:
>
> ... stuff <img alt="???" src="abc/def.x.y" /> ...other stuff
>
> I can assume <img..../> is all on one line.
>
> Thanks.

' <img alt="???" src="abc/def.x.y" /> '[/src="(.*?)"/,1]

Jeff Schwab

4/28/2006 5:18:00 PM

0

William James wrote:
> itsme213 wrote:
>> I know I really should be able to do this but my best effort is quite
>> awkward. What is a simple regex way to find and extract the string
>> "abc/def.x.y" from the following:
>>
>> ... stuff <img alt="???" src="abc/def.x.y" /> ...other stuff
>>
>> I can assume <img..../> is all on one line.
>>
>> Thanks.
>
> ' <img alt="???" src="abc/def.x.y" /> '[/src="(.*?)"/,1]
>

Wow, that's cool.

Rupert Bear

4/12/2011 4:29:00 PM

0

On Apr 12, 2:39 pm, Special Care <special.car...@gmail.com> wrote:
> In reply to:https://groups.google.com/group/uk.legal/browse_thread/thre......
>
> --------------------------------------------------------------------
>
> If you make a complaint against the health service, NHS or private, or
> are suspected of causing offence to them in some way, word gets
> around, at least regionally, and you could be ‘a marked man,’ denied
> access to services you are entitled to and ‘flagged’ for possible
> retaliation.
>
> As for doctors abusing people who are helpless on the operating
> table…. I know Dr Robert Mendelsohn died on the operating table when
> he seemed to his readers to be in robust health, but beyond that
> nobody will say anything about it. A lot of medical / vivisection
> profiteers wanted Dr Robert Mendelsohn out of the way.
>
> -------------
>
> I’m also reminded of Patrick Hackett.
> His case is just obliquely relevant to what you described, and is
> quite interesting, although very much a taboo subject in both England
> and Ireland.
>
> Patrick Hackett is the man who never was. Nobody wants to talk about
> him. He’s an embarrassment to all.
>
> In the 1970s, Dotty O’Connell, IRA boss in Dublin, was recruiting
> ignorant, impressionable young southern Irish boys to go over to
> London to blow up as many innocent civilians as possible, as part of
> their ‘struggle for freedom’….
>
> At about 4.30 pm one sunny day in 1975, Patrick Hackett got onto the
> ‘underground’ train at a northern terminal, Upminster, carrying a bomb
> timed to explode later in central London in a crowded carriage at the
> height of the rush hour (with Patrick Hackett intending to be at a
> safe distance from it). A few miles outside Upminster, the bomb
> started to smoke and exploded prematurely, as Patrick Hackett
> desperately threw it away from him toward the other end of the
> carriage. The train stopped between stations. Patrick Hackett ran
> away, covered in blood. When locals approached him to try to help him,
> he pointed a gun at them screaming: “English bastards.”
>
> Patrick Hackett did time in an English jail, minus an arm and a leg.
>
> This raises some interesting questions.
>
> You know how high above the ground those London trains are. Between
> stations, with no platform, it’s a bit difficult to get out of them,
> and then to run away, especially if you are so badly injured that you
> later are judged by doctors to need amputation of an arm and a leg.
>
> You see the contradiction. How did Patrick Hackett get out of the
> train between stations and run away, if he was so badly injured that
> he later needed an arm and a leg amputated?
>
> He was under police guard when taken to hospital. Nod nod, wink wink.
> If his bomb had gone off in a crowded carriage in central London, as
> he intended, many innocent people would have lost arms and legs. Nod
> nod, wink wink.
>
> I often used those London trains in the 1970s. Although I’m a man who
> can get agitated about corruption and injustice, I’ve not shed any
> tears over Patrick Hackett’s arm and leg. I doubt if any civil
> rights / malpractice lawyer or campaigner, of whatever nationality,
> would want to complain on his behalf, then or now. It’s a taboo
> subject. Not much fun being Patrick Hackett, the man who never was,
> the man who is only an embarrassment to everybody.

Well,,
I never heard of Hackett before,,, but if he got done unkindly on the
table,,, at least he would have known why...
If I had ever done anything against my GP's,, one might be able to
rationalise and say OK. fair doo's...
But I have no such luxury of having deserved it in any way,,,
the circumstances of my complaint are completely unacceptable and
intolerable...

I have been meaning to get back to this thread for a while but todal
asked a question about letters and i am having difficulty trying to
locate them...

............................................