in reply to Re: [OT] Thoughts on Ruby's new absent operator?
in thread [OT] Thoughts on Ruby's new absent operator?

> Anyway, I get the idea that (?~abc) would be analogous to ^x, except that the former is for multi-character sequences.

Thanks, now I get the idea and I have to admit that I missed this feature in the past, though I can't recall when exactly.

But all useful use-cases which come to my mind involve strict boundaries, like parsing a grammar and explicitely excluding certain commands.

Like parsing a html but not wanting "a" and "img"-tags while allowing "anchor"

This would mean to use something like

 /<\s*\b(?~a|img)\b(.*)>/

and this should be achievable with

use strict; use warnings; undef $/; $_ = <DATA>; # slurp print "1: $1 - $2\n" while /<\s*(?!a\b|img\b)(\w+)\b(.*?)\s*>/g; print "2: $1 - $2\n" while /<\s*(?!a|img)(\w+)(.*?)\s*>/g; my %absent = ( a=>1, img =>1 ); while (/<\s*(\w+)(.*?)\s*>/g) { print "3: $1 - $2\n" unless $absent{$1}; } while (/<\s*(\w+)\b(??{ $absent{$1} ? '^' : '' })(.*?)\s*>/g) { print "4: $1 - $2\n"; } __DATA__ <a href='bla'> <img href='bla'> <table style=""> <anchor > <tr width=100>

1: table - style="" 1: anchor - 1: tr - width=100 2: table - style="" 2: tr - width=100 3: table - style="" 3: anchor - 3: tr - width=100 4: table - style="" 4: anchor - 4: tr - width=100

please note how important it is to repeat the delimiting \b in case 1, which might justify the use of (?~...) .

Though to be sure I'd need to test the Ruby implementation, and I'm not willing to install yet.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

PS: Choosing HTML as data grammar was - as always - unfortunate. You are free to propose something different.