


java regular expression introduction to regular expression functions in PHP
Regular Expression (Regular Expression)
Regular expression system:
1.POSIX
2.Perl
The regex used in PHP is PCRE:
NOTE: PCRE (Perl Compatible Regular Expressions, Perl Compatible Regular Expressions)
PCRE syntax:
1. Delimiters
Must appear in pairs, you can use any character except 0-9a-zA-Z
2. Atom
1. The visible and invisible characters that the regular expression needs to match are all atoms
2. A regular expression The expression contains at least one atom
3. When you need to match semantic symbols such as "(", "[", "^" and other semantic symbols, you need to use "" backslash to escape
Atomic character:
f matches the form feed character
n matches newline character
r matches carriage return character
t matches tab character
v matches vertical tab character
3. Metacharacter
Escape character
^ matches the beginning of the string
$ matches the end of the string
. match Any single character except "n"
* Matches the previous subexpression 0 or more times
+ Matches the previous subexpression 1 or more times
? Matches the previous subexpression 0 or 1 times
{ n} matches n times
{n,} matches n times or more
{n,m} matches at least n times and at most m times, (n<=m)
[] The square brackets represent the atom table, the atoms in the middle The status is equal. When matching, match any character in the table
[^] and exclude the characters contained in the following atomic table.
(pattern) matches pattern and obtains this match. The numth matching reference.
(?:pattern) matches pattern but does not obtain this match
ute quo=pattern) utebilt (?=pattern) lainvicous (?=pattern) Matches pattern but does not get this match Windows in Windows
(?<=pattern) Reverse affirmative search, non-obtaining matching. For example: (?<=My|Postgre)SQL can match SQL in MySQL, but cannot match SQL in MSSQL
(? b matches word boundaries
B matches characters other than word boundaries
d matches any number. Equivalent to [0-9]
D matches any character other than a number. Equivalent to [^0-9]
s matches any whitespace character (including space, tab, form feed, etc.). Equivalent to [fnrtv]
S matches any non-whitespace character. Equivalent to [^fnrtv]
w matches any number, letter or underscore. Equivalent to [0-9a-zA-Z]
W matches any character that is not a number, letter, or underscore. Equivalent to [^0-9a-zA-Z]
4. Pattern modifier
i is not case-sensitive
m If there is a carriage return or line feed in this pattern, ^ and $ will match the beginning and end of each line.
s allows . to match n
If you add a carriage return after the string, $ can still match it successfully. But after adding D, the carriage return at the end no longer matches
NOTE: Regular expressions are matched from left to right
Related functions:
preg_filter — perform a regular expression search and replace
preg_grep — return the matching pattern Array entries
preg_last_error — Returns the error code generated by the last PCRE regular expression
preg_match_all — Performs a global regular expression match
Preg_replace — Perform a regular expression search and replace using a callback
Preg_split — Split a string by a regular expression
The above has introduced the regular expression function in java regular expression in PHP, including the content of java regular expression. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Java regular expression syntax detailed explanation and practical guide Introduction: Regular expression is a powerful text processing tool that can match, find and replace strings through a specific grammar rule. In the Java programming language, regular expressions can be used through the classes provided by the Java.util.regex package. This article will introduce the syntax of Java regular expressions in detail and provide practical code examples. 1. Basic syntax: 1. Single character matching: -Character class: expressed by square brackets [], indicating from the character sequence

An in-depth analysis of Java regular expression syntax requires specific code examples. Regular expressions are a powerful pattern matching tool that is widely used in various programming languages. In Java, we can use the classes provided by the java.util.regex package to implement regular expression functions. This article will delve into the syntax of Java regular expressions and illustrate it with specific code examples. 1. Basic syntax matching characters In regular expressions, we can use ordinary characters to match the same characters. For example

Java Regular Expressions Advanced Application Guide Introduction: Regular expressions are a powerful text pattern matching tool. Regular expressions can be used to perform various complex search, replacement and extraction operations in strings. In Java, regular expressions are implemented through classes provided by the java.util.regex package. This article will introduce readers to the advanced applications of Java regular expressions and provide specific code examples. 1. Basic concepts and syntax 1.1 Basic concepts of regular expressions Regular expressions are composed of characters and special words

The PatternSyntaxException class represents an unchecked exception thrown when a syntax error occurs in a regular expression string. This class contains three main methods namely - getDescription() - returns the description of the error. getIndex() - Returns the error index. getPattern() - Returns the regular expression pattern in which the error occurred. getMessage() - Returns the complete message containing the error, the index, the regular expression pattern in which the error occurred, and the error in the indicated pattern. Example Real-time demonstration importjava.util.Scanner;importjava.util.regex.Matcher;i

Java is a widely used programming language that provides powerful character processing capabilities, including the ability to use regular expressions. Regular expressions are a pattern matching tool that is very useful for quickly finding, replacing, validating, and extracting specific patterns and data when working with text and strings. Regular expressions in Java use the java.util.regex package. Classes in this package include Pattern and Matcher, which provide the core functionality of regular expressions.

Java regular expression syntax example: Matching email addresses and mobile phone numbers, specific code examples are required Regular expressions are a powerful text matching tool that can be used to extract and match required information from text. In Java, using regular expressions requires using the related classes and methods provided by the java.util.regex package. This article will introduce how to use regular expressions to match email addresses and mobile phone numbers, and give specific code examples. 1. The format of matching email addresses is usually "username@domain name", where username and domain

Java is a popular programming language that provides powerful regular expression tools to improve efficiency when processing strings. A regular expression is a pattern that describes a set of strings and can be used to perform pattern matching, find, and replace operations. In the following article, we will learn how to use regular expressions in Java. Regular expression syntax Java's regular expressions are based on the regular expression syntax of the Perl language and include some Java-unique syntax. Regular expressions are composed of characters and special characters.

How to use regular expression functions for string matching and replacement in Java Introduction: In Java programming, we often need to match and replace strings. These operations can be achieved using regular expression functions, a powerful pattern matching tool. This article will introduce how to use regular expression functions to match and replace strings in Java, and provide specific code examples. 1. Using regular expressions for string matching In Java, we can use Patte
