- Open source implementations of regular expressions: Regexkitlite (non-ARC) Use this class and need to import a dependent library: Libicucore.dylib
- NSString *text = @ "Zhang San: 010-88669900, li 4,232 phone 010-55443322 send 0731-8373834 garbage fee";
- 1. Defining Regular Expressions
- NSString *regex = @ "\\d{3,4}-\\d{7,8}";
- 2. Create a regular Expression implementation object
- Nsregularexpression *expression = [[Nsregularexpression alloc] Initwithpattern:regex options: Nsregularexpressioncaseinsensitive Error:nil];
- 3. Expression finds a string that conforms to a regular expression
- Nsarray *items = [Expression matchesinstring:self options:nsmatchingreportprogress range:nsmakerange (0, Self.length)] ;
- Nsmutablearray *itemarray = [Nsmutablearray array];
10.//4. Looping through the found results
- For (Nstextcheckingresult *result in items) {
- The range of strings that conform to the expression
- Nsrange range = [Result range];
- NSString *matchstring = [self substringwithrange:range];
- [ItemArray addobject:matchstring];
- }
- Nsrange RG = [text Rangeofregex:regex];
- NSString *substring = [text Substringwithrange:rg];
Recommended Learning site: http://www.jb51.net/tools/zhengze.html
Regular Expressions (open-source framework)