There won't be a unix standard that explicitly addresses your question.
Also standards, versus good working code are sometimes at odds (not that often).
I can think of at least 3 issues with code, even reg expressions, that as a developer I want to make are covered.
are the results correct? Only you can know this. Building your code as test-driven development isn't something that just java-people can do. Make a file with the range of inputs you think you should support, and make sure the output is working for all cases, AND if this is really a big project, have error messages showing what wasn't processed.
Is it maintainable? A block of comments detailing how you think the regular expression is working will be helpful to those that come after you, OR even for yourself 6 months from now, and you haven't looked at a reg-exp since.
Performance. Is there an alternate "phrasing" of the regular expression that still gives a correct answer, but "runs" faster?
Taking your reg-exp, I think I would have done it differently, given your definition. Note that this version is shorter, so by a very simple metric, it's easier to maintain.
temp=$(echo $file_timestamp \
| egrep '^20[0-9][0-9][0-1][0-9][0-3][1-9][0-2][0-9][0-5][0-9][0-5][0-9]$'
)
Unless you care to explain your use of ( .... )
grouping characters, I don't see any use for them.
(The only thing I can think of is that your specified format YYYYMMddhhmmss
is more flexible than you indicate. You're not trying to match any format of date the user might put it, i.e. YYYYMdhms (when there is a leading zero for any of the element?. Beware, this is a path to madness and incorrect data going into your system! ;-)
Finally, you don't indicate how you use $temp in your validation. I think a much simpler way to validate an existing variable (and more flexible) is to use a case statement. Try
case ${file_timestamp) in
20[0-9][0-9][0-1][0-9][0-3][1-9][0-2][0-9][0-5][0-9][0-5][0-9] )
print -u2 -- "dbg: valid : file_timestamp=${file_timestamp}"
# do other good stuff here
;;
* )
print -u2 -- "dbg:NOT valid : file_timestamp=${file_timestamp} "
# do other error reporting or fixing here
;;
esac
Now your avoiding extra processes for the $( ... ) and the grep
.
If you need your grouping chars like (2[0-9])
, then you'll have to use grep (sed, awk, etc) as ksh regexps don't support ()
grouping (I'm almost sure).
IHTH