Rob Dixon wrote at Thu, 27 Mar 2003 12:51:46 +0000:

> Janek Schleicher wrote:
>> >  $data = "David (man from uncle)";
>> >
>> >  $data = "John Doe (The boy down the hall)";
>> >
>> >   What I want to do is split $data into two string variables, one holding the
>> > $name, and the other holding all the $info that is within the parens. How
>> > would I do this? Thanks for any help.
>>
>> I would use a regexp:
>>
>> my ($name, $info) = $data =~ /(.*?)\w+\((.*)\)/;
> 
> Hi Janek.
> 
> I'm afraid your regex is wrong! It does the following:

Yep, it was a typo and untested.

>     capture zero or more (as few as possible) of any character
> !!  match one or more 'word' characters followed by an open parenthesis
>     capture zero or more (as many as possible) of any character
>     match a close parenthesis

Replace the \w+ with a \s* like of Stefan suggested,
an everything works fine :-)

The main advantage of a regexp solution against a split solution is that
it will also work with something like
$data = "Janek Schleicher (The (not yet) perfect regexp man :-))"


Greetings,
Janek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to