> 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.


In reply to Re^2: [OT] Thoughts on Ruby's new absent operator? by LanX
in thread [OT] Thoughts on Ruby's new absent operator? by perlancar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.