use strict; use warnings; my $textInner = '(outer(inner(most "this (shouldn\'t match)" inner)))'; my $innerRe; my $idx=0; my(@match); $innerRe = qr/ \( ( (?: [^()"]+ | "[^"]*" | (??{$innerRe}) )* ) \)(?{$match[$idx++]=$1;}) /sx; $textInner =~ /^$innerRe/g; print "$match[0]\n";
The regular expression has a recursive Pattern and searches for nested brackets but text with quotation marks is excluded.
So this script finds in (outer(inner(most "this (shouldn\'t match)" inner))):
most "this (shouldn't match)" inner
Now I was interested in the recursiv pattern and i searched for that.
I found this websites with some explantion for recursive patterns with PCRE:
http://regexkit.sour...yntax.html#TOC1
http://regexkit.sour...tern.html#SEC21
Ofcourse I want to build this Regexp with AHK.
This is my attempt for now:
str=(outer(inner(most "this (shouldn\'t match)"(hallo) inner))) reg=x)(\( ( (?:[^()"]+ | "[^"]*" | [color=red](?R)[/color] *) ) \)) r := RegExMatch(str, reg, s) msgbox,Pos=%r%`ns=%s%`ns1=%s1%`ns2=%s2%`ns3=%s3%But this don't stop at the quotationmarks.
it findsshouldn\'t match
Maybe somebody has an idea to make this regexp work.
I try this to learn how to work with recursion, so please show me solutions with recursiv regexp
item (?R).
Hopefully someone can put a light at this.
Thanks.