Re: regexp: ignoring nested brackets
- From: robic0
- Date: Mon, 02 Jan 2006 18:13:05 -0800
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!
.
- References:
- regexp: ignoring nested brackets
- From: Kaveh
- Re: regexp: ignoring nested brackets
- From: MSG
- Re: regexp: ignoring nested brackets
- From: Anno Siegel
- Re: regexp: ignoring nested brackets
- From: robic0
- Re: regexp: ignoring nested brackets
- From: Xicheng
- Re: regexp: ignoring nested brackets
- From: robic0
- Re: regexp: ignoring nested brackets
- From: Xicheng
- regexp: ignoring nested brackets
- Prev by Date: Re: regexp: ignoring nested brackets
- Next by Date: Re: regex bug?
- Previous by thread: Re: regexp: ignoring nested brackets
- Next by thread: Re: regexp: ignoring nested brackets
- Index(es):
Relevant Pages
|