![]() |
Please improve my n00b RegEx - Printable Version +- MacResource (https://forums.macresource.com) +-- Forum: My Category (https://forums.macresource.com/forumdisplay.php?fid=1) +--- Forum: Tips and Deals (https://forums.macresource.com/forumdisplay.php?fid=3) +--- Thread: Please improve my n00b RegEx (/showthread.php?tid=27680) |
Please improve my n00b RegEx - Greg the dogsitter - 02-08-2007 This is in Perl, if that matters. I have a string, called $base. I want it to match like so: gd_00000(five integers)_(14 integers, representing a date/timestamp).txt.gz For example: gd_0000012345_20070208092930.txt.gz I've come up with $base =~ /^gd_00000[0-9]{5}_[0-9]{14}.txt.gz/ Anything better? Thanks! GtDS Edit: Put in a ".". Or is that "put in a ".."? Re: Please improve my n00b RegEx - TheTominator - 02-08-2007 The only thing I might add is a $ on the end of the regexp to make sure that there is nothing after .txt.gz. Thus it would exclude ".txt.gz copy" for example. You also probably want to escape the "." so that it won't match any character. I think it would be "\." instead of "." . Re: Please improve my n00b RegEx - Greg the dogsitter - 02-08-2007 $ is the counterpart to ^; gotcha. Good idea on the dot, too. Thanks! |