The source code is as follows:
Copy Code code as follows:
-(Nsuinteger) Analyserx: (NSString *) string withpatternstring: (NSString *) patternstring
{
\\[[^\\]]+\\] to match the number of [*] occurrences in the string
<[^>]+> to match the number of <*> occurrences in the string
if (string = = nil)
{
return 0;
}
Regular expressions
Nsregularexpression *regex = \
[Nsregularexpression regularexpressionwithpattern:patternstring
Options:nsregularexpressioncaseinsensitive
Error:nil];
Perform related matching operations
Nsrange range = nsmakerange (0, [string length]);
Nsuinteger numberofmatches = [Regex numberofmatchesinstring:string
options:0
Range:range];
Returns the number of matches
return numberofmatches;
}
For example, if you want to query a string that appears in a few [* *] structure strings, like the following string:
Very simple, you can also replace the relevant string oh.
Experience:
This string looks for a string that appears in a style template with a regular expression, but you have no other way to do it: