← 返回工具集

正则表达式测试器

实时匹配测试、常用正则库、生成代码片段

匹配结果

常用正则表达式

邮箱地址

\b\w+@\w+\.\w+\b

手机号码

^1[3-9]\d{9}$

URL地址

https?:\/\/[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:/~+#]*[\w\-@?^=%&/~+#])?

日期格式

^\d{4}-\d{2}-\d{2}$

邮政编码

^\d{6}$

用户名

^[A-Za-z0-9_]{3,16}$

强密码

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$

金额格式

^\d+\.\d{2}$

代码生成

JavaScript
Python
Java
PHP
// JavaScript 代码示例
const pattern = /\b\w+@\w+\.\w+\b/g;
const text = "联系邮箱:test@example.com, admin@company.org";
const matches = text.match(pattern);
console.log(matches);
# Python 代码示例
import re
pattern = r'\b\w+@\w+\.\w+\b'
text = "联系邮箱:test@example.com, admin@company.org"
matches = re.findall(pattern, text)
print(matches)
// Java 代码示例
import java.util.regex.Matcher;
import java.util.regex.Pattern;

String pattern = "\\b\\w+@\\w+\\.\\w+\\b";
String text = "联系邮箱:test@example.com, admin@company.org";
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(text);
while (m.find()) {
    System.out.println(m.group());
}
// PHP 代码示例
$pattern = "/\\b\\w+@\\w+\\.\\w+\\b/";
$text = "联系邮箱:test@example.com, admin@company.org";
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);