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

Hi Monks, I put this out earlier, but how would you gather a job name as shown below that is not called 'New Job'? Basically, I want to capture any type of name that I give a job i.e. Testing01, mymusic, myimages2 etc. Could I use a character class here? As always, thanks for your time and I welcome your wisdom.

use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 1; my ($job); while(<DATA>){ chomp; next unless /Synchronizing started|Synchronizing finished|Summary/; my $summary; $summary++ if /Summary/; my $this_job; if (($this_job) = $_ =~ /"New Job (\d+)"$/){ $job = $this_job; } print qq{job: $job } if $summary; print qq{$_\n}; }; __DATA__ [4/14/2008 4:44 PM] Analyzing started, job: "New Job 1" [4/14/2008 4:45 PM] Synchronizing started, job: "New Job 1" [4/14/2008 4:45 PM] Analyzing finished, job: "New Job 1" [4/14/2008 4:45 PM] Synchronizing finished, job: "New Job 1" [4/14/2008 4:45 PM] Summary: Files processed: 6,554; Files copied: 1;

Replies are listed 'Best First'.
Re: Regex Character Class?
by Narveson (Chaplain) on Apr 19, 2008 at 05:34 UTC

    Yes, the \D character class will let you catch everything before the numbers in "Testing01" and "myimages2".

    printf "%20s %s\n", 'job_type', '#'; while (<DATA>) { my ($job_type, $job_number) = /job: "(\D+)(\d*)"\s*$/ or next; printf "%20s %s\n", $job_type, $job_number; } __DATA__ Prefatory remarks, job: "Testing01" More remarks, job: "mymusic" Other stuff, job: "myimages2"

    prints

    job_type # Testing 01 mymusic myimages 2
Re: Regex Character Class?
by wfsp (Abbot) on Apr 19, 2008 at 06:14 UTC
    I replied to your earlier question about this here.

    As noted in that reply you have to spell out exactly what it is you want to capture and what not to capture. The best bet is to give examples of each.

Re: Regex Character Class?
by apl (Monsignor) on Apr 19, 2008 at 11:48 UTC