Matlab Regular Expression for datetime string

1 回表示 (過去 30 日間)
Lili Xiao
Lili Xiao 2016 年 3 月 17 日
コメント済み: Lili Xiao 2016 年 3 月 17 日
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.
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 3 月 17 日
The question is not clear

サインインしてコメントする。

採用された回答

Walter Roberson
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.
  1 件のコメント
Lili Xiao
Lili Xiao 2016 年 3 月 17 日
Thank you very much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by