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!