/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/
0[1-7]
:匹配两位数,第一位是0,第二位是1到7。1[0-356]
:匹配两位数,第一位是1,第二位是0、3、5或6。2[0-7]
:匹配两位数,第一位是2,第二位是0到7。3[0-6]
:匹配两位数,第一位是3,第二位是0到6。4[0-7]
:匹配两位数,第一位是4,第二位是0到7。5[1-7]
:匹配两位数,第一位是5,第二位是1到7。6[1-7]
:匹配两位数,第一位是6,第二位是1到7。7[0-5]
:匹配两位数,第一位是7,第二位是0到5。8[013-6]
:匹配两位数,第一位是8,第二位是0、1、3、4、5或6。import re
pattern = r'^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$'
test_strings = ["011234", "157890", "220000", "360987", "475678", "517899", "618456", "705123", "804567", "091234", "185678", "290000", "376789", "488888", "559876", "678901", "799123", "827890", "12345", "1234567"]
for test_string in test_strings:
if re.match(pattern, test_string):
print(f"'{test_string}': 匹配成功")
else:
print(f"'{test_string}': 匹配失败")
const pattern = /^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/;
const testStrings = ["011234", "157890", "220000", "360987", "475678", "517899", "618456", "705123", "804567", "091234", "185678", "290000", "376789", "488888", "559876", "678901", "799123", "827890", "12345", "1234567"];
testStrings.forEach(testString => {
if (pattern.test(testString)) {
console.log(`'${testString}': 匹配成功`);
} else {
console.log(`'${testString}': 匹配失败`);
}
});
import java.util.regex.*;
public class RegexTest {
public static void main(String[] args) {
String pattern = "^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\\d{4}$";
String[] testStrings = {"011234", "157890", "220000", "360987", "475678", "517899", "618456", "705123", "804567", "091234", "185678", "290000", "376789", "488888", "559876", "678901", "799123", "827890", "12345", "1234567"};
for (String testString : testStrings) {
if (Pattern.matches(pattern, testString)) {
System.out.println("'" + testString + "': 匹配成功");
} else {
System.out.println("'" + testString + "': 匹配失败");
}
}
}
}
using System;
using System.Text.RegularExpressions;
class Program {
static void Main() {
string pattern = @"^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$";
string[] testStrings = {"011234", "157890", "220000", "360987", "475678", "517899", "618456", "705123", "804567", "091234", "185678", "290000", "376789", "488888", "559876", "678901", "799123", "827890", "12345", "1234567"};
foreach (string testString in testStrings) {
if (Regex.IsMatch(testString, pattern)) {
Console.WriteLine($"'{testString}': 匹配成功");
} else {
Console.WriteLine($"'{testString}': 匹配失败");
}
}
}
}
<?php
$pattern = '/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/';
$testStrings = ["011234", "157890", "220000", "360987", "475678", "517899", "618456", "705123", "804567", "091234", "185678", "290000", "376789", "488888", "559876", "678901", "799123", "827890", "12345", "1234567"];
foreach ($testStrings as $testString) {
if (preg_match($pattern, $testString)) {
echo "'$testString': 匹配成功\n";
} else {
echo "'$testString': 匹配失败\n";
}
}
?>
pattern = /^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/
test_strings = ["011234", "157890", "220000", "360987", "475678", "517899", "618456
", "705123", "804567", "091234", "185678", "290000", "376789", "488888", "559876", "678901", "799123", "827890", "12345", "1234567"]
test_strings.each do |test_string|
if pattern.match?(test_string)
puts "'#{test_string}': 匹配成功"
else
puts "'#{test_string}': 匹配失败"
end
end