正则表达式测试工具
工具加载中...
正在初始化 regex-tester-tool.html
常用正则表达式模式:
📧 邮箱地址
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
📅 日期格式
^\d{4}-\d{2}-\d{2}$
🔗 URL链接
^https?:\/\/[^\s]+$
🔒 强密码
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d@$!%*?&]{8,}$
🆔 身份证号
^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$
🌐 IP地址
\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
🎨 十六进制颜色
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
`);
}
function getPythonFlags(flags) {
const pythonFlags = [];
if (flags.includes('i')) pythonFlags.push('re.IGNORECASE');
if (flags.includes('m')) pythonFlags.push('re.MULTILINE');
if (flags.includes('s')) pythonFlags.push('re.DOTALL');
return pythonFlags.length > 0 ? pythonFlags.join(' | ') : '0';
}
function getJavaFlags(flags) {
const javaFlags = [];
if (flags.includes('i')) javaFlags.push('Pattern.CASE_INSENSITIVE');
if (flags.includes('m')) javaFlags.push('Pattern.MULTILINE');
if (flags.includes('s')) javaFlags.push('Pattern.DOTALL');
return javaFlags.length > 0 ? ', ' + javaFlags.join(' | ') : '';
}
// 实时测试功能
document.getElementById('regex').addEventListener('input', function() {
if (this.value && document.getElementById('testText').value) {
testRegex();
}
});
document.getElementById('testText').addEventListener('input', function() {
if (this.value && document.getElementById('regex').value) {
testRegex();
}
});
// 标志位变化时重新测试
document.querySelectorAll('input[type="checkbox"]').forEach(checkbox => {
checkbox.addEventListener('change', function() {
if (document.getElementById('regex').value && document.getElementById('testText').value) {
testRegex();
}
});
});