> On Saturday, June 13, 2015 06:59:21 AM Janis Papanagnou wrote:
> > It seems that ksh's "printf %R" is producing wrong results for negated 
> > glob-patterns:
> > 
> > $ printf "%R\n" "!(*bak)"
> > ^(.*bak)!$
> > 
> > $ echo $'abc\nabcbak\ndef' | grep -E '^(.*bak)!$'
> > ...empty result...
> > 
[...]
> 
> Is a regex equivalent to !() possible at all using any typical set of
> features? Since negative lookbehind generally doesn't support quantifiers
> I've never found a working solution even using fancy regex dialects. It
> likely requires conditional regex and some tricky use of (?R), if it's
> possible at all.

Yes, it's possible, just not as trivial as with the simple other forms (*, +, 
?),
where you can apply a  ("mechanical") one-to-one mapping and only have
to consider anchors.

(Someone recently explained it based on an example, but currently I cannot
find that Usenet(?) or StackExchange(?) posting.) You actually need to break
the simple form !(...) into a sequence of variants of sub-regexps with negated
character classes. Specificall there's no look-behind (or similar) necessary to
achieve that. The transformation is not trivial and error-prone to do by hand,
so an automatism (one that works) like the above mentioned "%R" would have
been really nice, specifically for the negation.

> 
> -- 
> Dan Douglas
> 
                                          
_______________________________________________
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to