While there are ways to work around nesting to a known depth, it gets
ugly quickly, and nesting to an arbitrary depth is beyond the ability
of regexes to match directly.
What you can do is write a parser that uses regular expression and
additional code to find the substring you are searching for.
search for "function"
set nestingLevel to 0
in a loop search for /[{}]/ opening a closing delimiter
if you find a { increment nestingLevel
if you find a } decrement it
when nesting level hits 0 again you are done
--- In [email protected], "marty.pitt" <[EMAIL PROTECTED]> wrote:
>
> Hi
>
> Can someone please give me a hand on a RegEx? (I can't work these
> things out for the life of me).
>
> I'm basically trying to return nested groups inside delimeters.
>
> An example we're all famililar with is the simple package / class
> structure in Flex:
>
> package foo {
> class bar {
> function stuff {
> ...
> }
> }
> }
> Given the delimeters oof { and }, I want to be able to return:
> function stuff {
> ...
> }
>
> As well as
>
> class bar {
> function stuff {
> ...
> }
> }
>
> etc., up the chain.
>
> I currently have the following regex working:
>
> {\d*?\D*?}
>
> Which works fine without nesting. As soon as you introduce nested
> elements, it all gets a bit messy.
>
> any help would be greatly appreciated.
>
> Cheers
>
> Marty
>