"Ranga Nathan" wrote: > > I use (?? to create drop in regex. However now there is a need to > actually execute some code and return a regex pattern. The postponed regex > operator (?? does not interpolate and does not seem to run any code other > than take an expression. Why? > Anyway to override this? I am looking at the possibility of creating a > custom regex module for this. Damian Conway's OO module has a chapter where he creates customized regular expression objects to do interesting stuff. You could look there for ideas. But... > This is for a project that requires parsing strings that are deeply nested > to varying degree sometimes delimiters can be used. Mostly the level of > nesting is identified by a numeric value. Anyone remembering COBOL would > be able to recall OCCURS DEPENDING ON in COBOL structure definitions. I am > taking it to the extreme level to create a generic script. ...right there that's your problem. REGULAR EXPRESSSIONS ARE FOR MATCHING PATTERNS, NOT FOR PARSING! (At least not until Perl 6 comes around.) If you want to parse, then use the regular expression engine as a tokenizer, and process tokens in code. You'll wind up using \G in your patterns and /cg in the flags a lot. (\G is described in perlre, /c and /g in perlop.) > Any experience / suggestion would be appreciated. And there is my suggestion. Rethink your approach. Don't use a regular expressions where they don't fit. Cheers, Ben