Regular expression for extracting date
I a regular expression to match a date on the form 01/Jan/2000:23:59:59. I
managed to match the pattern using Notepad++'s regex interpreter, using
the following regex:
[1-3][0-9]/[A-Z][a-z]{2}/(19|20)[0-9]{2}:[0-9]{2}:[0-5][0-9]:[0-5][0-9]
Unfortunately, I need to do this with bash. AWK is not an option right
now, I'm afraid. So, I tried to convert the above regex into something
that bash would interpret in the same way. Thus far, I've come up with
this:
[1-3][0-9]/[A-Z][a-z]\{2\}/(19|20)[0-9]\{2\}:[0-2][0-9]:[0-5][0-9]:[0-5][0-9]
The full command I'm using is
expr "$line" :
'\([1-3][0-9]/[A-Z][a-z]\{2\}/(19|20)[0-9]\{2\}:[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\)'
where $line contains the string out of which I need to extract the date.
Unfortunately my bash version of the regex doesn't work. I have tried
different things, like escaping / and :, but I can't seem to get it to
work. What am I doing wrong?
No comments:
Post a Comment