Follwing is a "pure regex" approach. It may of interest/useful if:

Win8 Strawberry 5.8.9.5 (32) Fri 08/11/2023 14:59:13 C:\@Work\Perl\monks >perl use strict; use warnings; use Test::More; use Test::NoWarnings; my @Tests = ( 'ALL these should match', # match # string success [ '<FILENAME>.htm' => 1, ], [ '<FILENAME>dp198076_424b2-us2342673.htm' => 1, ], [ 'fizz <FILENAME>dp198076_424b2-us2342673.htm fuzz' => 1, ], 'NONE of these should match', [ '' => '', ], [ ' ' => '', ], [ 'xxx' => '', ], [ "\n\n\n" => '', ], [ '<FILENAME>dp198076_424b2-us2342673.htm <FILENAME>dp198076_exfilingfees.htm' => '', ], [ '<FILENAME>.htmfred' => '', ], # see pm#11153807 [ 'fizz <FILENAME>dp198076_424b2-us2342673.htm foo bar <FILENAME>dp198076_exfilingfees.htm fuzz' => '', ], [ 'fizz <FILENAME>dp198076_424b2-us2342673.htm foo <FILENAME>xxx.htm bar <FILENAME>dp198076_exfilingfees.htm fuzz' => '', ], [ '<FILENAME>xxx.htm<FILENAME>yyy.htm' => '', ], [ '<FILENAME>.htm<FILENAME>.htm' => '', ], ); # end @Tests my @additional = qw(Test::NoWarnings); # each of these adds 1 test plan 'tests' => (scalar grep { ref eq 'ARRAY' } @Tests) + @additional ; my $rx_once = qr{ <FILENAME> (?: (?! [.]htm) .)* [.]htm \b }xms; VECTOR: for my $ar_vector (@Tests) { if (not ref $ar_vector) { note $ar_vector; next VECTOR; } my ($string, $expected) = @$ar_vector; my $got = $string =~ m{ \A (?: (?! $rx_once) .)* # no match before single match $rx_once # match just once (?: (?! $rx_once) .)* # no match after single match \Z }xms; is $got, $expected; } # end for VECTOR ^Z 1..14 # ALL these should match ok 1 ok 2 ok 3 # NONE of these should match ok 4 ok 5 ok 6 ok 7 ok 8 ok 9 ok 10 ok 11 ok 12 ok 13 ok 14 - no warnings

Update: Note that as the code stands, the test vector
    [ '<FILENAME>.htm<FILENAME>.htmfred' => 1, ]
will match/pass, i.e., will be accepted as having no duplication. Should this be the case?


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


In reply to Re: pattern matching once by AnomalousMonk
in thread pattern matching once by justin423

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.