Programming |
The following character combinations represent specific character and numeric values.
Octal and Hexadecimal -- \o, \x
Use \x
and \o
in an expression to find a comma (hex 2C
) followed by a space (octal 40
) followed by the character 2
:
numstr = 'Easy as 1, 2, 3'; [mat idx] = regexp(numstr, '\x2C\o{40}2', 'match', 'start') mat = ', 2' idx = 10
Special Characters -- \char
Use \
before a character that has a special meaning to the regular expression functions if you want that character to be interpreted literally. The intention in this example is to have the string '(ab[XY|Z]c)' interpreted literally. The first expression does not do that because regexp
interprets the parentheses and | sign as the special characters for grouping and logical OR:
This next expression uses a \ before any special characters. As a result the entire string is matched:
Character Classes | Logical Operators |
© 1994-2005 The MathWorks, Inc.