[Ruby] regex question
shaners becker
veganstraightedge at gmail.com
Mon Feb 12 15:52:45 PST 2007
i tried both eric's and aaron's suggestions. neither worked for me.
i'm in textmate, i've got some xml that i want to simplify. i should
be able to do just that with some find and replace, right? so here's
a shortened sample of what i have, in case that matters.
<recommendations>
<book asin="1563898683" aspect="Paperback" author="Jeph
Loeb
Tim Sale" country="us" created="190891680"
currentValue="$11.58" fullTitle="Batman: Dark Victory" genre="Action
& Adventure
Comics & Graphic
Novels
Contemporary
Batman
Adventure &
Thrillers
Fantasy
DC Comics
Superheroes"
lastLookupTime="190891680" netrating="4.5" pages="392" price="$19.99"
published="01-10-2002" publisher="DC Comics"
purchaseDate="19-01-2007" title="Batman: Dark Victory"
upc="9781563898686" uuid="76AE1DE0-DB14-4ED3-9201-C919F2F88A68">
</book>
<book asin="1563894696" aspect="Paperback" author="Jeph
Loeb
Tim Sale" country="us" created="190891680"
currentValue="$10.00" fullTitle="Batman: The Long Halloween"
genre="Action & Adventure
Comics & Graphic
Novels
Contemporary
Batman
Science
Fiction
Adventure & Thrillers
DC
Comics
Superheroes" lastLookupTime="190891680" netrating="4.5"
pages="369" price="$19.99" published="01-11-1999" publisher="DC
Comics" purchaseDate="19-01-2007" title="Batman: The Long Halloween"
upc="9781563894695" uuid="E33D943C-9CA5-4C39-BC0B-D2A05476A019">
</book>
</recommendations>
i'm trying to rip out all of the recommendations, so i'm left with
just my books in my library, not the ones i might want in my library.
so... i tried both:
/<recommendations>[^<]*<\/recommendations>/
/<recommendations>.*?<\/recommendations >/
neither of them found any results.
-sb
On Feb 12, 2007, at 11:23 AM, Eric Hodel wrote:
> On Feb 12, 2007, at 11:19, Aaron Patterson wrote:
>> On Mon, Feb 12, 2007 at 03:23:20AM -0800, shaners becker wrote:
>>> 2. just in textmate, i'm trying to do a find and replace that
>>> needs a
>>> regex. its an xml file and i want to remove all of one type of tag
>>> and its contents. say the tag is "book":
>>>
>>> <book>moby dick</book>
>>>
>>> how do i say find all: <book>...anything here...</book>?
>>
>> blah =~ /<book>[^<]*<\/book>/
>
> Also, a question mark turns a greedy match into a non-greedy match:
>
> blah =~ /<book>.*?<\/book>/
> _______________________________________________
> Ruby at zenspider.com - Seattle.rb non-commercial list
> http://www.zenspider.com/seattle.rb
> http://www.zenspider.com/mailman/listinfo/ruby
-----------
join the resistance. fall in love.
http://theresistancearmy.com/
More information about the Ruby
mailing list