regexp with _ recognized as a letter

3 ビュー (過去 30 日間)
Luca cadalo
Luca cadalo 2017 年 4 月 7 日
コメント済み: Guillaume 2017 年 4 月 7 日
when you use regexp regexp(Date, '(?<=Month=)\w+', 'match')
Date=Year2012_MonthMay_Day05
this character '_' is recognized as a letter??? so the information of the month can not be separated properly

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 4 月 7 日
\w does not match "letters"
"\w Any alphabetic, numeric, or underscore character. For English character sets, \w is equivalent to [a-zA-Z_0-9]"
If you want to match English letters then use [a-zA-Z]
  2 件のコメント
Luca cadalo
Luca cadalo 2017 年 4 月 7 日
so, in that case, you can not use \w
Guillaume
Guillaume 2017 年 4 月 7 日
No you cannot use \w. It's trivial to replace it with something that would work. I assume
regexp(Date, '(?<=Month)[^_]+', 'match')
would probably work for you. Note that I've removed the = you had after Month since it would have failed to match your example string.

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

カテゴリ

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