Stateflow | ![]() ![]() |
Specifying the Replacement Text
The Search & Replace tool replaces found text with the exact (case-sensitive) text you entered in the Replace With field unless you choose one of the dynamic replacement options described below.
Replacing with Case Preservation
If you choose the Case Preservation option, matched text is replaced based on one of the following conditions discovered in the found text:
"ANDREW"
, the found text "bill"
is replaced by "andrew"
.
"Andrew"
, the found text "BILL"
is replaced by "ANDREW"
.
"andrew johnson"
, the found text "Bill Monroe"
is replaced by "Andrew Johnson"
.
"andrew is tall."
, the found text "Bill is tall."
is replaced by "Andrew is tall."
.
Replacing with Tokens
Within a regular expression, you use parentheses to group characters or expressions. For example, the regular expression "and(y|rew)"
matches the text "andy"
or "andrew"
. Parentheses also have the side effect of remembering what they matched so that you can recall and reuse the found text with a special variable in the Replace with field. These are referred to as tokens.
Tokens outside the search pattern have the form $1,$2,...,$n (n<17)
and are assigned left to right from parenthetical expressions in the search string.
For example, the search pattern "(\w*)_(\w*)"
finds all word expressions with a single underscore separating the left and right sides of the word. If you specify an accompanying replacement string of "$2_$1"
, you can replace all these expressions by their reverse expression with a single Replace all. For example, the expression "Bill_Jones"
is replaced by "Jones_Bill" and
the expression "fuel_system"
is replaced by "system_fuel".
For a clearer understanding of how tokens are used in regular expression search patterns, see Regular Expressions in MATLAB documentation.
![]() | Using the Search Button and View Area | Using the Replace Buttons | ![]() |