Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please improve my n00b RegEx
#1
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 ".."?
Reply
#2
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 "." .
Reply
#3
$ is the counterpart to ^; gotcha.

Good idea on the dot, too. Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)