Matlab Regular Expression for datetime string
1 回表示 (過去 30 日間)
古いコメントを表示
Hi, I have string that contains time information. "this_file_05312016' here 05(month)31(day)2016(year) I am able to make it work for search January any day by using "01[01-31]+2016" Now I want to do search January - March, any day of 2016. I used [01-03][01-31]+2016 seems not working. What I might be missing? Thank you for your help.
採用された回答
Walter Roberson
2016 年 3 月 17 日
Least specific to dates:
0[1-3]\d\d2016
more specific:
0[1-3]([0-2][0-9]|3[01])2016
Even more specific:
(0[13]([0-2][0-9]|3[01])|02[0-2][0-9])2016
or more compactly,
(0[13]([0-2]\d|3[01])|02[0-2]\d)2016
extending the more specific to April or beyond would add more complexity. Extending the search to non-leapyears would add more complexity.
Often, the very first of those possibilities is good enough, if you already know that all the things that vaguely look like dates are going to be valid dates, and you are just concerned with selecting the right months. The more complex versions are suitable for the case where you might have mixed in other things that are not valid dates and you need to select only valid dates, such as if there was this_file_02302016 that you want to skip because of the invalid date, there never being a February 30th.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!