On Mar 8, 2014 1:41 AM, "shawn wilson" <ag4ve...@gmail.com> wrote:
>

Oh and per optional, just do (?:\([0-9]+).*\)?
You should probably use do
my @match = $str =~ / ([^]+)  (?:\([0-9]+).*\)? ([a-z]+)/;
my ($a, $b, $c) = (scalar(@match) == 3 ? @match : $match[0], undef,
$match[1]);

> ([^]+) \(([0-9]+).*\) ([a-z]+)
>
> On Mar 8, 2014 1:07 AM, "Bill McCormick" <wpmccorm...@gmail.com> wrote:
>>
>> I have the following string I want to extract from:
>>
>> my $str = "foo (3 bar): baz";
>>
>> and I want to to extract to end up with
>>
>> $p1 = "foo";
>> $p2 = 3;
>> $p3 = "baz";
>>
>> the complication is that the \s(\d\s.+) is optional, so in then $p2 may
not be set.
>>
>> getting close was
>>
>> my ($p1, $p3) = $str =~ /^(.+):\s(.*)$/;
>>
>> How can I make the " (3 bar)" optional.
>>
>> Thanks!
>>
>> ---
>> This email is free from viruses and malware because avast! Antivirus
protection is active.
>> http://www.avast.com
>>
>>
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> For additional commands, e-mail: beginners-h...@perl.org
>> http://learn.perl.org/
>>
>>

Reply via email to