I’m (a regex noob) trying to find only the files in a directory that begin with numbers and not strings.
My regex is
.*/^\d+\w+[A][D][0-5][0-9].mat
(The end of the file name has the letters AD and then numbers from 0-54 before the MAT extension. I include ./ because I am going to pass this to find in bash.)
However, this returns false for both files like
./times_121312_going_down_AD33.mat
and
./121312_going_down_AD33.mat
What am I doing wrong?
Here’s a working example with find
\dand\wdon’t work in POSIX regular expressions, you could use[:digit:]thoThe regular expression explained
.*repeat any character except\n, zero or more times/match character ‘/’ literally[0-9]+repeat any char in 0 to 9, one or more times_match character ‘_’ literally.*repeat any character except\n, zero or more timesAmatch character ‘A’ literallyDmatch character ‘D’ literally[0-5]Match any char in 0 to 5[0-9]Match any char in 0 to 9\.match ‘.’ literallymmatch ‘m’ literallyamatch ‘a’ literallytmatch ‘t’ literally$end of stringIf you just want to match all files beginning with an integer you can break it down to
.*/[0-9]which would also match./12/test.tmpand./12_not_a_mat_file.txt