regexp with _ recognized as a letter

2 vues (au cours des 30 derniers jours)
Luca cadalo
Luca cadalo le 7 Avr 2017
Commenté : Guillaume le 7 Avr 2017
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

Réponses (1)

Walter Roberson
Walter Roberson le 7 Avr 2017
\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 commentaires
Luca cadalo
Luca cadalo le 7 Avr 2017
so, in that case, you can not use \w
Guillaume
Guillaume le 7 Avr 2017
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by