ultranerds has asked for the wisdom of the Perl Monks concerning the following question:


Sorry, the subject isn't very descriptive, but wasn't sure how to describe what I'm trying to do =)

I have this string:

my $summary = q~[sommaire Bordeaux à test] [[Hébergement à Bordeaux]] [[Gastronomie à Bordeaux]] [[A voir à Bordeaux]] == a sub header === sub header == foo bar === whatever [[Sorties, vie nocturne à Bordeaux]] [[Suggestions pour Bordeaux]] [/sommaire] ~;

..what I need to do, is has a while () {} which will go through that string, and split it up into the following:

var 1: [[Bordeaux|A propos de Bordeaux]] var 2: [[Gastronomie à Bordeaux]] var 3: [[A voir à Bordeaux]] == a sub header === sub header == foo bar === whatever var 4: [[Sorties, vie nocturne à Bordeaux]] var 5: [[Suggestions pour Bordeaux]]

I've tried quite a few regexes, but I can't seem to get them right (I've just ordered the following book - but that won't arrive for a couple of days, I thought it would be worth my while to read it though, as there is still a ton of stuff I don't know about regexes - should of done this years ago!)



Replies are listed 'Best First'.
Re: Extract content from a string
by Corion (Patriarch) on Jan 05, 2011 at 11:46 UTC
      Eugh, why do I always have to overcomplicate things? =)

      Works like a charm - thanks :)


Re: Extract content from a string
by roboticus (Chancellor) on Jan 05, 2011 at 13:43 UTC


    I see you already have a solution to your immediate problem. But since the text looks like one of the myriad variations of a Wiki markup language, have you considered looking on for an appropriate parsing module?


    When your only tool is a hammer, all problems look like your thumb.

Re: Extract content from a string
by tubaandy (Deacon) on Jan 05, 2011 at 14:47 UTC
    ultranerds, glad you found the answer. One other note, a lot of the O'Reilly books are available via the iTunes app store (I don't work for Apple, or O'Reilly, just happened across this). If you have an iPod or iPad, it's an inexpensive way to get access to the books quickly. FWIW.

      How's the Ipad experience for reading the Perl Books? Are they well-formatted for reading?