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

Hi monks,

I have a doubt regarding Perl regex. Kindly help!

$data = "Job Opportunities Press Room Press Releases Background Library Image Gallery Press Contact Partner with us Areas of Interest Why Partner with Galderma Working Together Contact InformationSearch : Job Opportunities Working at Galderma Insider's View Job Opportunities SENIOR DATA MANAGER M/W France (Ref. SA/SDM0713/GRD) Position Status CDI Job Description GALDERMA, joint-venture between Nestlé and L'Oréal, is o +ne of the Pharmaceutical leaders in Dermatology. GALDERMA develops an +d markets therapeutic, corrective and aesthetic innovative solutions +and procedures to prevent, diagnose and cure dermatologic diseases. W +e recruit for our R & D center in Sophia Antipolis (06) - France: SENIOR DATA MANAGER M/W";

I need the out put as

$output = "SENIOR DATA MANAGER M/W France (Ref. SA/SDM0713/GRD) Position Status CDI Job Description GALDERMA, joint-venture between Nestlé and L'Oréal, is o +ne of the Pharmaceutical leaders in Dermatology. GALDERMA develops an +d markets therapeutic, corrective and aesthetic innovative solutions +and procedures to prevent, diagnose and cure dermatologic diseases. W +e recruit for our R & D center in Sophia Antipolis (06) - France: SENIOR DATA MANAGER M/W";

basically I need only from the 3rd Job Opportunities. How can I achieve that?

Now I am doing  $output = $1 if ($data =~ /Job Opportunities(.*)/is); but this is not working exactly as I want Its taking after the 1st Job Opportunities, kindly Help!

Replies are listed 'Best First'.
Re: Regex Help!
by AnomalousMonk (Archbishop) on Jul 25, 2013 at 07:49 UTC

    \K available with Perl version 5.10+.

    >perl -wMstrict -le "my $s = 'xxx Job Opps foo bar Job Opps hoo ha Job Opps are real cool'; ;; my $job_opps = qr{ \b Job \s+ Opps \b }xms; my ($cool) = $s =~ m{ (?: $job_opps .*){2} $job_opps \K .* }xmsg; print qq{'$cool'}; " ' are real cool'
Re: Regex Help!
by hdb (Monsignor) on Jul 25, 2013 at 08:53 UTC

    Instead of using a regex, consider setting the record separator $/ to the string "Job Opportunities" when reading your data from a file (or split your data using this as the separator). The last item in the result will be what you are looking for.

Re: Regex Help!
by nemesdani (Friar) on Jul 25, 2013 at 07:33 UTC
    Look for the pattern /g - globally. Match in a loop. Count the occurences.


    I'm too lazy to be proud of being impatient.
Re: Regex Help!
by Loops (Curate) on Jul 25, 2013 at 07:42 UTC
    Is it that you want everything below the final "Job Opportunities" header? If so:
    my $output = ($data =~ s/.*Job Opportunities\n?//irs);
Re: Regex Help!
by mtmcc (Hermit) on Jul 25, 2013 at 08:16 UTC
    Don't be afraid to look at perlre. It doesn't bite, and you might just find what you're looking for.

    Best of luck.