MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Metacharacter Description Example


. Any single character, including white
space


'..ain' matches sequences of five
consecutive characters that end with
'ain'.

[c 1 c 2 c 3 ] Any character contained within the
square brackets. The following
characters are treated literally: $
|. * +? and - when not used to
indicate a range.


'[rp.]ain' matches 'rain' or 'pain'
or '.ain'.

[^c 1 c 2 c 3 ] Any character not contained within
the square brackets. The following
characters are treated literally: $
|. * +? and - when not used to
indicate a range.


'[^*rp]ain' matches all four-letter
sequences that end in 'ain', except
'rain' and 'pain' and '*ain'. For
example, it matches 'gain', 'lain', or
'vain'.

[c 1 -c 2 ] Any character in the range of c 1
through c 2


'[A-G]' matches a single character in
the range of A through G.

\w Any alphabetic, numeric, or
underscore character. For English
character sets, \w is equivalent to
[a-zA-Z_0-9]


'\w*' identifies a word.

\W Any character that is not alphabetic,
numeric, or underscore. For English
character sets, \W is equivalent to
[^a-zA-Z_0-9]


'\W*' identifies a term that is not a
word.

\s Any white-space character;
equivalent to [ \f\n\r\t\v]


'\w*n\s' matches words that end with
the letter n, followed by a white-space
character.

\S Any non-white-space character;
equivalent to [^ \f\n\r\t\v]


'\d\S' matches a numeric digit followed
by any non-white-space character.

\d Any numeric digit; equivalent to
[0-9]


'\d*' matches any number of
consecutive digits.

\D Any nondigit character; equivalent to
[^0-9]


'\w*\D\>' matches words that do not
end with a numeric digit.

\oN or \o{N} Character of octal value N '\o{40}' matches the space character,
defined by octal 40.


Regular Expressions
Free download pdf