Does my computer's locale affect the results of regular expressions in MATLAB?
2 views (last 30 days)
Show older comments
MathWorks Support Team
on 22 Jun 2015
Edited: MathWorks Support Team
on 11 Jan 2016
MATLAB's regular expression documentation states that:
\w represents any alphabetic, numeric, or underscore character. For English character sets, \w is equivalent to [a-zA-Z_0-9]
see: <http://www.mathworks.com/help/matlab/matlab_prog/regular-expressions.html>
I am using a non-English locale on my computer, so what does \w match?
Accepted Answer
MathWorks Support Team
on 11 Jan 2016
The \w metacharacter will match any "alphanumeric" character as defined by Unicode, which is locale independent.
For example:
str = 'Mit luftpudefartøj er fyldt med ål';
regexp(str,'\w*','match')
ans =
'Mit' 'luftpudefartøj' 'er' 'fyldt' 'med' 'ål'
In this example the characters ø and å are matched, even though they are not part of the standard English character set. The results of this code would be the same when run on a computer with any locale.
0 Comments
More Answers (0)
See Also
Categories
Find more on Language Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!