| Stateflow User's Guide | ![]() |
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:
In this case, the found text has no uppercase characters, only lowercase. Found text is replaced entirely with the lowercase equivalent of all replacement characters. For example, if the replacement text is "ANDREW", the found text "bill" is replaced by "andrew".
In this case, the found text contains only uppercase characters. Found text is replaced entirely with the uppercase equivalent of all replacement characters. For example, if the replacement text is "Andrew", the found text "BILL" is replaced by "ANDREW".
In this case, the found text contains uppercase characters in the first character position of each word. Found text is replaced entirely with the case equivalent of all replacement characters. For example, if the replacement text is "andrew johnson", the found text "Bill Monroe" is replaced by "Andrew Johnson".
In this case, the found text contains an uppercase character in the first character position of a sentence with all remaining sentence characters in lowercase. Found text is replaced in like manner, with the first character of the sentence given an uppercase equivalent and all remaining sentence characters set to lowercase. For example, if the replacement text is "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 | ![]() |
© 1994-2005 The MathWorks, Inc.