Intelligently generate and explain regular expressions, supporting various common pattern matching
Convert your text instructions into formulas or input a formula to have it explained.
Edit Excel online by chatting with AI
Convert your text instructions into SQL queries - powered by AI.
Generate Excel VBA (Visual Basic for Applications) code to automate tasks and create custom solutions within Microsoft Excel.
Upload your Excel file and generate beautiful charts with our AI-powered chart generator.
Convert your text into beautiful mind maps with our AI-powered mind map generator. Edit and customize your mind maps easily.
Use AI to intelligently generate and explain regular expressions, supporting various text pattern matching and data validation.
# Complete PHP Regular Expression Tutorial (with Common Examples) [2025 Most Comprehensive Guide]
Regular Expressions in PHP are powerful tools for string processing. This tutorial will provide a set of practical PHP regular expression examples, covering common matching needs like email, mobile numbers, URLs, Chinese characters, HTML tags, etc., helping developers quickly get started with using regex in PHP.
## ✅ Overview of Regular Expression Functions (preg series)
```php
preg_match() // Perform a regex match, return the first match
preg_match_all() // Perform a global regex match, return all matches
preg_replace() // Perform regex replacement
preg_split() // Split a string using a regular expression
preg_grep() // Filter an array based on a regex
$email = "[email protected]";
if (preg_match("/^[\w\-\.]+@([\w\-]+\.)+[a-zA-Z]{2,7}$/", $email)) {
echo "Valid Email";
}
$mobile = "13812345678";
if (preg_match("/^1[3-9]\d{9}$/", $mobile)) {
echo "Valid Mobile Number";
}
$url = "https://www.example.com";
if (preg_match("/^(https?:\/\/)?([\w\-]+\.)+[a-zA-Z]{2,6}(\/\S*)?$/", $url)) {
echo "Valid URL";
}
$ip = "192.168.0.1";
if (preg_match("/^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/", $ip)) {
echo "Valid IP";
}
$html = "<p>Hello <strong>world</strong></p>";
preg_match_all("/<[^>]+>([^<]+)<\/[^>]+>/", $html, $matches);
print_r($matches[1]);
$str = "你好world";
if (preg_match("/[\x{4e00}-\x{9fa5}]/u", $str)) {
echo "Contains Chinese";
}
$str = "abc123def456";
$result = preg_replace("/\d+/", "", $str);
echo $result; // Output abcdef
$str = "hello123world,php";
$parts = preg_split("/[^a-zA-Z]+/", $str);
print_r($parts);
Modifier | Description |
---|---|
i | Case-insensitive match |
m | Multiline mode |
s | Dotall mode (. matches newline) |
u | Support UTF-8 characters |
x | Ignore whitespace in pattern |
Usage:
preg_match("/pattern/i", $str); // Case-insensitive match
preg_match_all
to get all match results.
preg_replace
for batch string replacement.
u
modifier.
.
, *
, ?
,
(
, )
, +
, etc.
var_dump()
to debug regex results.