Regexkitlite use of the detailed

Source: Internet
Author: User
Tags character classes

1. Go to Regexkitlite download class library, extract will have an example package and 2 files, in fact, the use of the 2 files, added to the project.

2. Add Libicucore.dylib frameworks to the project.

Friendly reminder: General people import regexkitlite compile error, precisely because did not import this class library, plus this is OK

3. Now all NSString objects can invoke the method in Regexkitlite.

NSString *email = @ "[email protected]";

[Email ismatchedbyregex:@ "\\b ([a-za-z0-9%_.+\\-]+) @ ([a-za-z0-9.\\-]+?\\.[ a-za-z]{2,6}) \\b "];

Return yes to the email format, note that the regular expression used by Regexkitlite is slightly different from the wiki.

SearchString = @ "http://www.example.com:8080/index.html";

regexstring = @ "\\bhttps?:/ /[a-za-z0-9\\-.] + (?::(\\d+))? (?:(?:/ [A-za-z0-9\\-._?, ' +\\&%$=~*! (): @\\\\]*) +)? ";

Nsinteger Portinteger = [[searchstring stringbymatching:regexstring capture:1l] integervalue];

NSLog (@ "Portinteger: '%ld '", (long) portinteger);

2008-10-15 08:52:52.500 host_port[8021:807] Portinteger: ' 8080′

Take an example of HTTP in string.

Here are some common regular expressions (in fact, regexkitlite official online, afraid of cheating with shoes do not see)

Characterdescription\amatch a BELL, \u0007\amatch at the beginning of the input. differs from ^ in that \a won't match after A New-line within the input.\b, outside of a [set]match if the current posi tion is a word boundary. Boundaries occur at the transitions between word \w and Non-word \w characters, with combining marks ignored. See also:rklunicodewordboundaries\b, within a [Set]match a BACKSPACE, \u0008.\bmatch if the current position are not a wor D Boundary.\cxmatch a control-x character.\dmatch any character with the Unicode General Category of Nd (number, Decimal D igit). \dmatch any character that's not a decimal digit.\ematch an ESCAPE, \u001b.\eterminates a \q...\e quoted SEQUENCE.\FM Atch a FORM FEED, \u000c.\gmatch if the current position are at the end of the previous Match.\nmatch a line feed, \u000a.\ N{unicode Character Name}match The named Unicode Character.\p{unicode property Name}match any Character with the specified Unicode Property.\p{unicode Property Name}match anyCharacter not have the specified Unicode property.\qquotes all following characters until \e.\rmatch a carriage RETURN, \u000d.\smatch a white space character. White space is defined as [\t\n\f\r\p{z}].\smatch a non-white space character.\tmatch a horizontal tabulation, \u0009.\uhh Hhmatch the character with the hex value hhhh.\uhhhhhhhhmatch the character with the hex value HHHHHHHH. Exactly eight hex digits must be provided, even though the largest Unicode code point is \u0010ffff.\wmatch a word charact Er. Word characters is [\p{ll}\p{lu}\p{lt}\p{lo}\p{nd}].\wmatch a Non-word character.\x{h ...} Match the character with hex value HHHH. From one to six hex digits is supplied.\xhhmatch the character with the digit hex value hh.\xmatch a grapheme Cluster. \zmatch if the current position are at the end of input, but before the final line terminator, if one exists.\zmatch if the Current position are at the end of Input.\nback Reference. Match whatever the nth capturing group matched. N MusT is a number≥1 and≤total number of capture groups in the pattern. Note:octal escapes, such as \012, is not supported. [Pattern] Match any one character from the set. See ICU Regular Expression Character Classes for a full description of the "What is appear in the pattern." Match any character.^match on the beginning of a line. $Match at the end of a line.\quotes the following character. Characters that must is quoted to be treated as literals is *? + [() {} ^ $ | \./operatorsoperatordescription| Alternation. a| B matches either A or b.*match zero or more times. Match as many times as possible.+match one or more times. Match as many times as possible.? Match zero or one times. Prefer one. N Match exactly n times. {N,} Match at least n times. Match as many times as possible. {N,m} Match between N and M times. Match as many times as possible, but isn't more than m.*? Match zero or more times. Match as few times as possible.+? Match one or more times. Match as few times as possible.?? Match Zero OR One times. Prefer Zero. {n}? Match exactly n times. {N,}? Match at least n times, but no more than required for an overall pattern match. {n,m}? Match between N and M times. Match as few times as possible, but isn't less than than n.*+match zero or more times. Match as many times as possible when first encountered, does not retry with fewer even if overall match fails. Possessive Match.++match one or more times. Possessive match.? +match zero or one times. Possessive match. {N}+match exactly n times. Possessive match. {N,}+match at least n times. Possessive match. {N,m}+match between N and M times. Possessive match. (...) Capturing parentheses. Range of input that matched the parenthesized subexpression was available after the match. (?:...) non-capturing parentheses. Groups the included pattern, but does not provide capturing of matching of text. Somewhat more efficient than capturing parentheses. (...) Atomic-match parentheses. First match of the parenthesized subexpression is the only one tried; If it does not The lead to an overall pattern match, back up the search for a match to a position before the (?>. #...) Free-format comment (? #comment). (? = ...) Look-ahead assertion. True if the parenthesized pattern matches at the current input position, but does not advance the input position. (?! ...) Negative Look-ahead assertion. True If the parenthesized pattern does not match at the current input position. Does not advance the input position. (? <= ...) Look-behind assertion. True if the parenthesized pattern matches text preceding the current input position and the last character of the match Being the input character just before the current position. Does not alter the input position. The length of possible strings matched by the look-behind pattern must isn't be unbounded (no * or + operators). (?<!...) Negative Look-behind assertion. True If the parenthesized pattern does not match text preceding the current input position, with the last character of the Match being the input character just before the CUrrent position. Does not alter the input position. The length of possible strings matched by the look-behind pattern must isn't be unbounded (no * or + operators). (? ISMWX-ISMWX: ...) Flag settings. Evaluate the parenthesized expression with the specified flags enabled or-disabled. (? ismwx-ismwx) Flag settings. Change the flag settings. Changes apply to the portion of the pattern following the setting. For example, (? i) changes-a case insensitive match. See Also:regular Expression Options

Also note is the escape character Oh ~ ~ Copy on safari will be converted directly (website pretty humane)

Also available are conversion tools, safari test support, may be slow to download, patience waiting, links

Regexkitlite use of the detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.