Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find Date as Regexp
#1
I need to find a date in the form dd/mm/20yy in a string. The following code works. I wonder whether there exists something better - more elegant. Many thanks in advance.

Function tempf10
Code:
Copy      Help
,
str sl="WEIKS (E.4223/2013)     IZ DDY     2016     28/08/2016 TamTzu"
str ss

int i=findrx(sl "\d\d[/]\d\d[/]\Q20\E\d\d" 0 0 ss)
if(i>=0) out ss
#2
I have a program called regx buddy, the examples below are from an older license I have. Below you see examples from the library of that program.
I didn't see the need to upgrade to the newest version but can not guarantee if the examples below from the regx buddy program are still up to date.
Note:
  • Each description below states "Matches invalid dates such as February 31st", but the regex doesn't match 'February 31st' maybe I understood wrong or description is not fully correct. (I don't know).
  • Within the application there are several types of flavours (Perl, Java,...) the regex engine used for the below library examples are based from it's own regex engine, you probably need to change it to work properly in QM.

I hope you might have some use for it.


Quote:Date d/m/yy and dd/mm/yyyy
1/1/00 through 31/12/99 and 01/01/1900 through 31/12/2099
Matches invalid dates such as February 31st
Accepts dashes, spaces, forward slashes and dots as date separators

Code:
Copy      Help
\b(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]{2}\b


-------------------------------

Quote:Date dd/mm/yyyy
01/01/1900 through 31/12/2099
Matches invalid dates such as February 31st
Accepts dashes, spaces, forward slashes and dots as date separators

Code:
Copy      Help
(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}



-------------------------------

Quote:Date m/d/y and mm/dd/yyyy
1/1/99 through 12/31/99 and 01/01/1900 through 12/31/2099
Matches invalid dates such as February 31st
Accepts dashes, spaces, forward slashes and dots as date separators

Code:
Copy      Help
\b(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2}\b

-------------------------------

Quote:Date mm/dd/yyyy
01/01/1900 through 12/31/2099
Matches invalid dates such as February 31st
Accepts dashes, spaces, forward slashes and dots as date separators

Code:
Copy      Help
(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)[0-9]{2}


-------------------------------

Quote:Date yy-m-d or yyyy-mm-dd
00-1-1 through 99-12-31 and 1900-01-01 through 2099-12-31
Matches invalid dates such as February 31st
Accepts dashes, spaces, forward slashes and dots as date separators

Code:
Copy      Help
\b(19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])\b


-------------------------------
Quote:Date yyyy-mm-dd
1900-01-01 through 2099-12-31
Matches invalid dates such as February 31st
Accepts dashes, spaces, forward slashes and dots as date separators

Code:
Copy      Help
(19|20)[0-9]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])
#3
Thank you, I find it very useful !


Forum Jump:


Users browsing this thread: 2 Guest(s)