Lookahead/behind are zero-width assertions; you are asserting that after matching ^ (beginning of string), what comes just before that can't be XDG_, and then continuing to match the rest of your regex. There are two problems here: first, the beginning of the string will never follow XDG_, so your assertion will always pass; and second, you will only match if the string ends with _PATH or _PATH followed by a newline, which doesn't meet your requirements.
If perl supported variable length lookbehind, you could use a lookbehind at the end:
/^[_A-Z0-9]+$(?<!^XDG_.*_PATH)/
but it doesn't. So use a lookahead instead, to test that the entire string is the expected characters but doesn't match your exclusion at the beginning:
/^(?!XDG_.*_PATH$)[_A-Z0-9]+$/
or (and this is almost always the more readable approach), do it in code:
/^[_A-Z0-9]+$/ && ! /^XDG_.*_PATH$/
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.