Nick Diel wrote:
> I am having a hard time getting a regular expression to work the way
> i want it to.  Take the following text: bla bla bla (la la) bla bla
> (di da) 
> 
> I want to extract the la la to one variable  and di da to antoher
> variable. What I have tried so far is using match variables, but so
> far I am only able to match either just la la or la la) bla bla (di
> da. 

To grab the stuff in parens:

   my @matches = $var =~ /\((.*?)\)/g;

@matches will contain 'la la' and 'di da'. You could assign to separate vars
with:

   my ($la, $di) = $var =~ /\((.*?)\)/g;

How it works:

   \(  = match an open paren
   (   = start capturing
   .   = match any char...
   *   = ...zero or more times
   ?   = shortest string...
   )   = end capture...
   \)  = followed immediately by closing paren
   /g  = do this repeatedly, returning list of all captured strings

HTH.

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

Reply via email to