newpat = maskedPattern(pat)
creates a pattern that uses the input name of pat when displaying the
pattern expression of newpat. You can use
maskedPattern to simplify long, complicated pattern expressions by
hiding some of the details in the expression.
The displayed pattern expression is long and difficult to read. Use maskedPattern to display the variable name, mathSymbols, in place of the pattern expression.
Use maskedPattern to display a specified name in place of the pattern expressions. Build a pattern using the masked patterns that find words that start and end with D followed by a word that starts and ends with R.
dWordsPat = maskedPattern(dWordsPat,"Words that start and end with D");
rWordsPat = maskedPattern(rWordsPat,"Words that start and end with R");
dAndRWordsPat = dWordsPat + whitespacePattern + rWordsPat
dAndRWordsPat = pattern
Matching:
Words that start and end with D + whitespacePattern + Words that start and end with R
Show all details
Create a string, and then extract the pattern from the text.
txt = "Dad, look at the divided river!";
words = extract(txt,dAndRWordsPat)
words =
"divided river"
Create custom pattern functions and use
maskedPattern to hide details.
Create a function atLeastOneOfPattern that takes the input
pattern pat and creates a pattern, newPat, that
matches one or more consecutive instances of pat. Use
maskedPattern to hide the details of the pattern when
displayed.
function newPat = atLeastOneOfPattern(pat)
arguments
pat patternend
newPat = asManyOfPattern(pat,1);
newPat = maskedPattern(newPat,compose("atLeastOneOfPattern(%s)",pat));
end
Call atLeastOneOfPattern with the input "a"
and display newPat.
newPat = atLeastOneOfPattern("a")
newPat =
pattern
Matching:
atLeastOneOfPattern("a")
Show all details
Create a pattern hexDigit that matches numeric characters from 0-9 and letters from a-f with characterListPattern. Since characterListPattern is case sensitive, use caseInsensitivePattern so that hexDigit matches regardless of character case.
hexDigit = pattern
Matching:
hexDigit
Show all details
hexDigit matches individual digits of hexadecimal numbers. Match full hexadecimal numbers by building a pattern that matches the literal text "0x" followed by one or more occurrences of hexDigit.
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window.
Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: United States.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.