Re: regexp: ignoring nested brackets



On 2 Jan 2006 17:40:32 -0800, "Xicheng" <xicheng@xxxxxxxxx> wrote:

>I just did a little revisement on Jeffrey's code and apply it on the
>problem of OP..He actually counted the numbers of the opening and
>closing brackets to control the matching of regex..
>#############################################
>$_='\mymacro{abcd {abcdgte{asdfSA}ksd} {ASDFD}sdfsd} ;laksjd;lkfajs';
>
>my $pattern = qr{
> (?> (?{$b=0}) # count the number of braces
> (?:
> # Stuff not braces
> [^{}]+
> # An opening brace
> | \{ (?{$b++})
> # A closing brace
> | \} (?(?{$b !=0 }) (?{$b--}) | (?!))
> )*
> ) (?(?{$b != 0}) (?!)) #fail if no balanced brace found
>}x;
>
>print "$1\n" while /\s\{($pattern)\}/g;
>##############################################
>#the resulting output:
>abcdgte{asdfSA}ksd
>ASDFD
>##############################################
>Looks good so far, didnt try some more complex data anyway....
>Xicheng
>
Hey, you can't rely on anything (?...), didn't you read the
documentation? Why is that anyway?
Why write a single code case that works for a simple problem
with (?..) when a single character change of script makes it
invalid? The whole thing is completely rediculous. The flaw
is regex is that it can't handle a "phrase" as an entity
in any of its quatifiers. Its a serious flaw that indicates
the true "character" nature of regex. This nature has to be
abstracted out to include phrases. There is not workaround
or alternative idom for that. And there never will be.
If the engine has to grow to accomodate larger space for thos
than it should be re-writen.

In all honesty, phrases are treated as constants, while
a class is treated as a variable. The class can contain only
characters. But man, a class item can include a phrase...
can't it? Its a simple thing. Yes it introduces an expansion
on a couple of levels, bet man without it, regex is practically
useless. In my opinion there should be any connotation in classes
above characters, including logical phrases, and/or/xor/not on
a phrase level. Its such a simple thing to do. I'm just sick
Perl is loaded with such a lack luster group of ... maintainers!
.



Relevant Pages

  • Re: regexp: ignoring nested brackets
    ... which proposed a way to do it in a sigle regex. ... > "Matching Nested Constructs with Embedded Code" ... > beginning form of the phrase. ... > Its a serious flaw and requires a redisign of the engine. ...
    (comp.lang.perl.misc)
  • Re: Stumped with simple regular expression
    ... > My regular expression inadequacies are surfacing again... ... > I'm trying to write a simple regex to match either the character S, ... > the character O, or the phrase SP (but not the phrase SO, or SP, or any ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: replace variable with same variable
    ... David wrote: ... variable into the regex replace phrase or can it be done within the ... -- Larry Wall ...
    (comp.lang.perl.misc)
  • Re: Match and cut regex?
    ... [This followup was posted to comp.lang.perl.misc] ... > If I have a 'cut' phrase: ... > What regex do I use to match the ABBCCCD and then chop off everything ... use English; ...
    (comp.lang.perl.misc)
  • Stumped with simple regular expression
    ... My regular expression inadequacies are surfacing again... ... I'm trying to write a simple regex to match either the character S, ... the character O, or the phrase SP (but not the phrase SO, or SP, or any ...
    (microsoft.public.dotnet.languages.csharp)