Programming |
A regular expression is a string of characters that defines a certain pattern. You would normally use a regular expression in searching through text for a group of words that matches this pattern, perhaps while parsing program input, or while processing a block of text.
The string 'Joh?n\w*'
is an example of a regular expression. It defines a pattern that starts with the letters Jo
, is optionally followed by the letter h
(indicated by 'h?'
), is then followed by the letter n
, and ends with any number of non-whitespace characters (indicated by '\w*'
). This pattern matches any of the following:
MATLAB supports most of the special characters, or metacharacters, commonly used with regular expressions and provides several functions to use in searching and replacing text with these expressions.
This section discusses the following topics:
MATLAB Regular Expression Functions
Several MATLAB functions support searching and replacing characters using regular expressions:
Function |
Description |
regexp |
Match regular expression. |
regexpi |
Match regular expression, ignoring case. |
regexprep |
Replace string using regular expression. |
See the function reference pages to obtain more information on these functions. For more information on how to use regular expressions in general, consult a reference on that subject.
Shell Escape Functions | Elements of an Expression |
© 1994-2005 The MathWorks, Inc.