http://www.perlmonks.org?node_id=880577

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

Hi,

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!)

http://www.amazon.co.uk/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124/ref=sr_1_3?s=books&ie=UTF8&qid=1294227606&sr=1-3

TIA!

Andy

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 :)

      Cheers

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

    ultranerds:

    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 http://search.cpan.org for an appropriate parsing module?

    ...roboticus

    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.

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