1 Introduction:2 3 Regular expressions, also known as formal notation, conventional notation (English: Regular expression, often abbreviated in code as regex, RegExp, or re), is a concept of computer science. A regular expression uses a single string to describe and match a series of strings that conform to a certain syntactic rule. In many text editors, regular expressions are often used to retrieve and replace text that conforms to a pattern. 4 5 6 .: matches any single character. For example, the regular expression "B.G" can match the following string: "Big", "Bug", "B g", but does not match "Buug", "B." G "Can match" Buug ". 7[]: Matches any one of the characters in the parentheses. For example, the regular expression "b[aui]g" matches the bug, big and bag, but does not match beg, Baug. You can use the hyphen "-" in parentheses to specify a range of characters to simplify the representation, such as regular expressions [0-9] can match any numeric character, so the regular expression "a[0-9]c "equivalent to" a[0123456789]c "can match" a0c "," A1c "," a2c "and other strings, you can also create multiple intervals, such as" [A-za-z] "can match any uppercase and lowercase letters," [a-za-z0-9] "can match any uppercase or lowercase letters or numbers. 8| : A logical OR operation of two matching criteria.'Z|food'Can match"Z"Or" Food"。'(z|f) Ood'Then match"Zood"Or" Food". 9 Ten One (): the expression that is enclosed in () is defined as "group", and the character that matches the expression is saved to a staging area, which is useful when the string is extracted. To represent some characters as a whole. Change the priority, define the extraction group of two roles. A*: Match 0 to more sub-expressions before it, and wildcards * okay. For example, the regular expression "zo*" can Match "Z", "Zo" and "Zoo", so ". *" means that you can match any string."Z (b|c) *"→ZB, ZBC, ZCB, ZCCC, ZBBBCCC."Z (AB) *"can match Z, Zab, Zabab (with parentheses to change precedence). -+: Matches the preceding subexpression one or more times, and * contrasts (0 to multiple). For example, the regular expression + + matches 9, About, 999 and so on. "zo+" can Match "Zo" and "Zoo", not match"Z". - the -? : matches the preceding subexpression 0 or one time. For example"Do (es)?"Can match" Do"Or"does". Typically used to match the "optional section". -{n}: matches the determined n times. "Zo{2} "→zoo. For example, "e{2} "cannot match" E "in" bed ", but can match two" E "in" seed ". -{N,}: matches at least n times. For example, "e{2,} "cannot match" E "in" bed ", but can match all" E "in" Seeeeeeeed ". +{n,m}: matches at least n times and matches up to M times. "E{1,3} "will match the first three" E "in" Seeeeeeeed ". - + A^: Non-operational a[^b] Except for the characters B thinks at\d: Represents a number, equivalent to [0-9] -\d: Represents a non-numeric equivalent to [^0-9] - \s: Represents a line break, Tab tab, and other whitespace characters - \s: Represents non-whitespace characters - \w: Matches letters or numbers or underscores or kanji, which are characters that can form words -\w: Non-\w, equivalent to [^\w] in - to + - the * $ Panax Notoginseng- (void) Viewdidload - { the [Super Viewdidload]; + //additional setup after loading the view, typically from a nib. A the //Regular Expressions + //. is a match to any one character -NSString *text =@"AB"; $NSString *regex =@"a.b"; $ //[self evaluatewithstr:text regex:regex]; - //nspredicate *predicate = [Nspredicate predicatewithformat:@ "Self MATCHES%@", regex]; - // the //if ([predicate evaluatewithobject:text]) { - //NSLog (@ "match request");Wuyi //}else{ the //NSLog (@ "mismatch requirement"); - // } Wu - //[] matches any one of the characters in the parentheses. About[Self evaluatewithstr:@"AC"Regex:@"A[a-z]"]; $ - //|: The expression defined as "group" between two matching criteria for logic () -[Self evaluatewithstr:@"AB"Regex:@"A (a|b)"]; - A //*: Match 0 to more sub-expressions before it +[Self evaluatewithstr:@"a"Regex:@"A *"]; the - //+: Match previous subexpression one or more times $[Self evaluatewithstr:@"AA"Regex:@"A +"]; the the the //?: Match previous subexpression 0 or one time the[Self evaluatewithstr:@" Do"Regex:@"Do (es)?"]; - in the //{n}: Match determined n times the[Self evaluatewithstr:@"doooo"Regex:@"Do{3}"]; About the //{n,}: matches at least n times the[Self evaluatewithstr:@"dooo"Regex:@"do{3,}"]; the + //{n,m}: Match n-m times -[Self evaluatewithstr:@"doooo"Regex:@"do{2,3}"]; the Bayi //\d: Represents a number the[Self evaluatewithstr:@"2234"Regex:@"\\d*"]; the - //\w: Matches letters or numbers or underscores or kanji -[Self evaluatewithstr:@"2"Regex:@"\\w"]; the the //write an expression for a mailbox the //[email protected] the[Self evaluatewithstr:@"[email protected]"Regex:@"[A-za-z0-9_]*@[a-za-z0-9]* (\\.[ a-za-z]*) {A}"]; - the } the the 94-(void) Evaluatewithstr: (NSString *) str regex: (NSString *) regex{ theNspredicate *predicate = [Nspredicate predicatewithformat:@"Self MATCHES%@", regex]; the the if([predicate evaluatewithobject:str]) {98NSLog (@"Matching Requirements"); About}Else{ -NSLog (@"Mismatch requirements");101 }102}
iOS Regular expressions