... the (*SKIP)(*FAIL) trick ... looked interesting, but does not seem applicable here.

I, too, have been trying to press this trick into service for this application and all my efforts have ended in tears.

... how does one determine that [some character] has been seen before?

The (*SKIP)(*FAIL) trick works with interpolations, variable alternations and variably-quantified atoms that are known at compile time. But as you noted, you can't know what characters you will encounter in an arbitrary string until run time, and then it's too late. Maybe that's why such impure practices as  (?{ ...code... }) were invented in the first place.

... doubting whether it is possible at all with pure regexes ...

I'm slowly and reluctantly being driven to this conclusion myself — but I haven't yet given up all hope!

(BTW: I don't consider a solution fully acceptable unless it can be adapted to extract all singleton characters from a string in one pass. All the "pure" solutions I've seen so far only seem to work for a single singleton per string. Oh, well...)


Give a man a fish:  <%-{-{-{-<


In reply to Re^4: Regex: matching character which happens exactly once by AnomalousMonk
in thread Regex: matching character which happens exactly once by LanX

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.