match - Match a sting with a regular expression
match(string search_in,string pattern [, character search_pattern_option])
Searches search_in for a match to the regular expression given in pattern
. This function is using PCRE (Perl-compatible Regular Expressions) to search the patterns. For more detail, please refer to to PCRE documentation page https://www.pcre.org/original/doc/html/
search_in
required, the string to search in.
'i': PCRE_CASELESS;
'a': PCRE_ANCHORED;
'm': PCRE_MULTILINE;
's': PCRE_DOTALL;
'x': PCRE_EXTENDED;
'U': PCRE_UNGREEDY;
'r': PCRE_BSR_ANYCRLF;
'u': PCRE_BSR_UNICODE;
'e': PCRE_DOLLAR_ENDONLY;
'd': PCRE_DOTALL;
'f': PCRE_FIRSTLINE;
'j': PCRE_JAVASCRIPT_COMPAT;
'n': PCRE_NEWLINE_ANY;
'N': PCRE_NEWLINE_ANYCRLF;
'c': PCRE_NEWLINE_CR;
'l': PCRE_NEWLINE_CRLF;
Here are the detailed explaination of the options:PCRE_ANCHORED Force pattern anchoring PCRE_AUTO_CALLOUT Compile automatic callouts PCRE_BSR_ANYCRLF \R matches only CR, LF, or CRLF PCRE_BSR_UNICODE \R matches all Unicode line endings PCRE_CASELESS Do caseless matching PCRE_DOLLAR_ENDONLY $ not to match newline at end PCRE_DOTALL . matches anything including NL PCRE_DUPNAMES Allow duplicate names for subpatterns PCRE_EXTENDED Ignore white space and # comments PCRE_EXTRA PCRE extra features (not much use currently) PCRE_FIRSTLINE Force matching to be before newline PCRE_JAVASCRIPT_COMPAT JavaScript compatibility PCRE_MULTILINE ^ and $ match newlines within data PCRE_NEVER_UTF Lock out UTF, e.g. via (*UTF) PCRE_NEWLINE_ANY Recognize any Unicode newline sequence PCRE_NEWLINE_ANYCRLF Recognize CR, LF, and CRLF as newline sequences PCRE_NEWLINE_CR Set CR as the newline sequence PCRE_NEWLINE_CRLF Set CRLF as the newline sequence PCRE_NEWLINE_LF Set LF as the newline sequence PCRE_NO_AUTO_CAPTURE Disable numbered capturing paren- theses (named ones available) PCRE_NO_AUTO_POSSESS Disable auto-possessification PCRE_NO_START_OPTIMIZE Disable match-time start optimizations PCRE_NO_UTF16_CHECK Do not check the pattern for UTF-16 validity (only relevant if PCRE_UTF16 is set) PCRE_NO_UTF32_CHECK Do not check the pattern for UTF-32 validity (only relevant if PCRE_UTF32 is set) PCRE_NO_UTF8_CHECK Do not check the pattern for UTF-8 validity (only relevant if PCRE_UTF8 is set) PCRE_UCP Use Unicode properties for \d, \w, etc. PCRE_UNGREEDY Invert greediness of quantifiers PCRE_UTF16 Run in pcre16_compile() UTF-16 mode PCRE_UTF32 Run in pcre32_compile() UTF-32 mode PCRE_UTF8 Run in pcre_compile() UTF-8 mode
Returns an array of matched result, which is a list of arrays of matched strings.
Note: In the followings examples, the _ between the { should be removed to make it work.
res={_{ match("Pierre 56a Laplante 65b chantal 72c caroline", "", "i");// return *regular expression is empty.* match("Pierre 56a Laplante 65b chantal 72c caroline", "(\d\d\d\d-\d\d)", "i");// return [], an empty array. match("Pierre 56a Laplante 65b chantal 72c caroline", "(\d+)([A-Z]+)", "i"); // return [["56","a"],["65","b"],["72","c"]]. match("Pierre 56a Laplante 65b7 chantal 72c7 caroline", "(\d+)([A-Z]+)(\d)", "i");// return [["65","b","7"],["72","c","7"]]. }}.
{{ include("includes/strings.sn") }}
Written by Xueyuan Peng, <xueyuanp@sednove.com>
Edit© 2024 extenso Inc. All rights reserved.