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!