Javascript Regular Expression Pattern modifier Daquan key Regular Expressions/I,/g,/ig,/gi,/m difference and meaning

Source: Internet
Author: User

Php + ajax + json provincial/municipal drop-down lists are linked. json transmission is used to verify that parameters are transmitted during login.
The following code is reserved as a mark:
Function (data ){
// Alert (data );
Var data1 = data. replace (/\ s/gm ,"");
Var data2 = data. match (/\ [(. *) \]/g ,"");
// Alert (data2 );
.............
}
 
The key is to understand the differences between the following pattern modifiers: www.2cto.com
 
Perl-style Regular Expressions allow you to place a single character option (FLAG) behind the regular expression mode to modify the matching interpretation or behavior. For example, to perform case-insensitive matching, you can simply use the I flag:
Preg_match ('/cat/I', 'Stop, Catherine! '); // Returns true if returns is true.
Table 4-12 shows the modifiers from Perl supported in Perl-Compatible Regular Expressions:
Table 4-12: Perl flag
Modifier meaning
/Regexp/I case-insensitive matching
/Regexp/s match the period (.) with any character, including the line break (\ n)
/Regexp/x remove blank spaces and comments from the Mode
/Regexp/m make ^ match the content after the line break (\ n), and the dollar sign ($) matches the content before the line break (\ n)
/Regexp/e if the replacement string is PHP code, run eval () to obtain the actual replacement string.
 
PHP's Perl-Compatible Regular Expression functions also support other modifiers not supported in Perl, as shown in Table 4-13:
Table 4-13: Other PHP flags
Modifier meaning
/Regexp/U reverse the greedy nature of the sub-mode; * matches as little as possible with + rather than as much as possible.
/Regexp/u treat pattern strings as UTF-8 Encoding
/Regexp/X if a backslash followed by a character with no special meaning, an error will be generated.
/Regexp/A positions the anchor at the beginning of the string, just as if there is A ^ in the pattern.
/Regexp/D make $ match only the end of a row
/Regexp/S enables the expression parser to check the structure of the pattern with greater care and speed up the second Runtime (such as in a loop)
Author: ibmfahsion

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.