Home  >  Article  >  Backend Development  >  Introduction to PHP regular expressions /i, /is, /s, /isU, etc., regular expression isu_PHP tutorial

Introduction to PHP regular expressions /i, /is, /s, /isU, etc., regular expression isu_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:16:291076browse

Introduction to PHP regular expressions /i, /is, /s, /isU, etc., regular expression isu

What are the PHP regular expressions /i, /is, /s, /isU, etc.?

i is not case sensitive

The dot metacharacter (.) in the

s pattern matches all characters, including the newline character

Whitespace characters in the

x pattern are completely ignored except those that are escaped or within a character class, # outside of an unescaped character class, and all characters between the next newline character, inclusive, Also ignored

A (PCRE_ANCHORED) If this modifier is set, the pattern is forced to be "anchored", that is, it is forced to match only from the beginning of the target string, that is, ^ is automatically added to the beginning of the pattern.

D (PCRE_DOLLAR_ENDONLY) If this modifier is set, dollar metacharacters in the pattern only match the end of the target string. Without this option, if the last character is a newline character, the dollar sign will also match before that character (but not before any other newline character). This option is ignored if the m modifier is set. There is no equivalent modifier in Perl. S When a pattern is going to be used several times, it is worth analyzing it first to speed up matching. If this modifier is set additional analysis will be performed. Currently, analyzing a pattern is only useful for non-anchored patterns that do not have a single fixed starting character.

U (PCRE_UNGREEDY) This modifier inverts the value of the number of matches so that it is not repeated by default, but becomes repeated when followed by a "?" This is not compatible with Perl. This option can also be enabled by setting the (?U) modifier in the mode.

X (PCRE_EXTRA) This modifier enables an extra feature in PCRE that is incompatible with Perl. Any backslash in the pattern followed by a letter with no special meaning results in an error, thus preserving this combination for future expansion. By default, like Perl, a backslash followed by a letter with no special meaning is treated as the letter itself. No other traits are currently controlled by this modifier. That is: greedy mode, maximum matching such as: /a[w]+?e/U matches abceade in abceadeddd instead of abce. If no U correction is added, it matches abce u (PCRE_UTF8). This modifier enables a PCRE Extra functionality that is incompatible with Perl. Pattern strings are treated as UTF-8. This modifier is available since PHP 4.1.0 under Unix and since PHP 4.2.3 under win32.

PHP regular expression problem: /<[^>]*?>*?<\/>/si This is an expression that filters all scripts. Can you explain it in detail?

Add "?" to indicate non-greedy matching...

The parameter "i" indicates to ignore case

The parameter "s" indicates that "." in the regular expression can match newlines

php regular match /href=\'([\S\s]*)\'/isU

preg_match("/href=\'([\S\s]*)\'/", $str, $match);echo $match[1]; //This is the match inside the brackets

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/898282.htmlTechArticleIntroduction to PHP regular expressions /i, /is, /s, /isU, etc., regular expression isu PHP regular expression What are the expressions /i, /is, /s, /isU, etc.? i is case-insensitive. Dot metacharacters in s mode...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn