Get the App
SLTechnology News&Howtos  ›  Development  › 

Several styles of regular expression syntax are supported in PHP

Shulou Source: shulou.com Published: 2022-06-03 11:11:57 11月15日 Update

This article mainly shows you the "PHP supports several styles of regular expression syntax", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "PHP supports several styles of regular expression grammar" this article.

PHP supports two styles of regular expression syntax: POSIX and Perl. POSIX-style regular expressions are easier to master, but they are not safe for binary patterns, while Perl-compatible regular expressions are relatively complex.

A regular expression is a string pattern consisting of ordinary characters (such as aplasz) and special characters (called metacharacters). Using regular expressions, you can do the following: ① tests a pattern of a string; ② replaces text; and ③ extracts a substring from the string based on pattern matching.

1. POSIX style regular expressions

1. Write regular expressions

Regular expressions are composed of ordinary characters and metacharacters. Regular expressions with different meanings can be written through different combinations of metacharacters and ordinary characters.

POSIX regular expression syntax format list

Character description\ escape character, used to escape special characters. ^ matches the starting position of the input string. $matches the end of the input string. * matches the previous subexpression zero or more times. + matches the previous subexpression one or more times. ? Matches the previous subexpression zero or once. {n} n is a non-negative integer that matches a determined n times. {n,} n is a non-negative integer that matches at least n times. {n ·m} m} m and n are non-negative integers, where n

Tags: Character string function expression regular array pattern search syntax escape number octal style size unit parameter format result that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Docker Xiaomi Microsoft Shulou Information