PHP regular expression function library (two sets)

There are two sets of regular expression function libraries in PHP, both have similar functions, but the execution efficiency is slightly different: One set is provided by the PCRE (Perl Compatible Regular Expression) library. Use the “preg_” prefix to name the function;The set provided by the POSIX (Portable Operating System Interface of Unix) extension (PHP default). Use functions prefixed with “ereg_”; In PHP, regular expressions have three functions: Matching is also often used to extract information from strings. Replaces matching text with new text. Breaks a string into a set of smaller chunks of information. A regular expression must contain at least one atom. Atoms (ordinary characters, such as English characters) Metacharacters (characters with special functions) Pattern correction characters (modifications to the semantics of regular expressions) Atoms (Atom) Single character, number, such as a~z, A~Z, 0~9. A model unit, such as (ABC), can be understood as a large atom composed of multiple atoms. Atom table, such as [ABC]. Reused pattern units, such as: \\1 Common escape characters, such as: \d, \D, \w Escape metacharacters, such as: \*, \. POSIX regular expressionPOSIX regular expression is called Portable Operating System Interface of Unix, which means the portable operating system implementation interface of…

Regular expression functions in php There are two sets of regular expression function libraries in php. One is, PHP regular expression function library (two sets)…

$string = “April 15, 2003”; $pattern = “/(\w+) (\d+), (\d+), (\d+ 43;)/i”; $replacement = “\${1}1,\$3”; print preg_replace($pattern, $replacement, $string ); preg_match_all() for global regular expression matching Grammar format : preg_match_all (“|]+>(. *)[^>]+>|U”, “example: this is a test”, $out, PREG_PATTERN_ORDER) ; print $out[0][0].”, “.$out[0][1].” “; print $ out[1][0].”, “.$out[1][1].” “; Output result :example: , this is a test example: , this is a test Original :http://www.jb51.net/article/20400.htm

Regular expression functions in php There are two sets of regular expression function libraries in php. One is, PHP regular expression function library (two sets)…

$string = “April 15, 2003”; $pattern = “/(\w+) (\d+), (\d+), (\d+ 43;)/i”; $replacement = “\${1}1,\$3”; print preg_replace($pattern, $replacement, $string ); preg_match_all() for global regular expression matching Grammar format : preg_match_all (“|]+>(. *)[^>]+>|U”, “example: this is a test”, $out, PREG_PATTERN_ORDER) ; print $out[0][0].”, “.$out[0][1].” “; print $ out[1][0].”, “.$out[1][1].” “; Output result :example: , this is a test example: , this is a test Original :http://www.jb51.net/article/20400.htm

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索