in reply to Driving the Engine right off the road

/^(?<!XDG_) [_A-Z0-9]+ _PATH$/x does not make sense to me, you are trying to look before the beginning of the string.

How about:

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11166082 use warnings; my @patterns = qw/PKG_CONFIG_PATH XDG_DATA_DIRS XDG_SEAT_PATH XDG_SESS +ION_PATH/; my $re = qr/^(?!XDG_ [_A-Z0-0]+ _PATH$)/x; for ( @patterns ) { print /$re/ ? " match" : "no match", " $_\n"; }

Outputs:

match PKG_CONFIG_PATH match XDG_DATA_DIRS no match XDG_SEAT_PATH no match XDG_SESSION_PATH

Replies are listed 'Best First'.
Re^2: Driving the Engine right off the road
by ysth (Canon) on Aug 24, 2025 at 14:31 UTC
    That will also match "bob", which doesn't sound desired.

      It correctly performs on all the provided test cases. It's not my problem if an inadequate number of test cases are provided :)

        $string eq 'PKG_CONFIG_PATH' || $string eq 'XDG_DATA_DIRS'
        then? 😀