in reply to regex assistance for parsing arg list

As with most regular expressions, the following is assuming a whole lot. For example that there are not more embedded functions in the functions that occur inside the first function. Also that there are only 4 arguments (parameters?) passed to the first function. Lastly that there are no spaces between the argument and the comma. You might have to modify this to get the spacing (adding \s in places and whatnot. Anyhow here is some code that might work for your purpose:
use strict; use warnings; while ( <DATA> ) { my $string = $_; if ( $string =~ /func[A-Za-z]\( (func[A-Za-z]\([^\)]+\)|[^,]+) #looks for a function a +nd if not found then ,(func[A-Za-z]\([^\)]+\)|[^,]+) #grab everything to the +comma ,(func[A-Za-z]\([^\)]+\)|[^,]+) ,(func[A-Za-z]\([^\)]+\)|[^,]+)\)/x) { print "FOR STRING: $string", '$1 = ',$1,$/, '$2 = ',$2,$/, '$3 = ',$3,$/, '$4 = ',$4,$/,$/; } } __DATA__ funca(1,2,3,4) funca(funcH(A,B,C),2,3,4) funca(1,funcH(A,B,C),3,4) funca(1,2,funcH(A,B,C),4) funca(1,2,3,funcH(A,B,C))
Updated:Removed some of the ugliness from the formatting in code.

-enlil

Replies are listed 'Best First'.
Re: Re: regex assistance for parsing arg list
by ihb (Deacon) on Feb 04, 2003 at 19:45 UTC

    But what happens when you have a function call as funcH's argument? You've just nestled the code, but the the exception that the outer can take privitive function calls as arguments. You could easily turn this pattern into a recursive dito though. Check out the (??{}) assertion in perlre and it should be pretty trivial.

    Cheers,
    ihb