Have a perl script that needs to process all files of a certain type from a given directory. The files should be those that end in .jup, and SHOULDN’T contain the word ‘TEMP_’ in the filename. I.E. It should allow corrected.jup, but not TEMP_corrected.jup.
Have tried a look-ahead, but obviously have the pattern incorrect:
/(?!TEMP_).*\.jup$/
This returns the entire directory contents though, including files with any extension and those containing TEMP_, such as the file TEMP_corrected.jup.
The regular expression you want is:
The main difference is that your regular expression is not anchored at the start of the string, so it matches any substring that satisfies your criteria – so in the example of
TEMP_corrected.jup, the substringscorrected.jupandEMP_corrected.jupboth match.(The other difference is that putting
()round both the lookahead and the.ensures that TEMP_ isn’t allowed anywhere in the string, as opposed to just not at the start. Not sure whether that’s important to you or not!)If you’re getting files other than
.jupfiles, then there is another problem – your expression should only match.jupfiles. You can test your expression with:then type strings: perl will echo them back if they match, and not if they don’t. For example: