/^\d{15,17}$/
"123456789012345"
(15 个数字)"1234567890123456"
(16 个数字)"12345678901234567"
(17 个数字)"12345678901234"
(不足 15 个数字)"123456789012345678"
(超过 17 个数字)"12345678901234a"
(包含非数字字符)"12345678901234 "
(包含空格)import re
pattern = r'^\d{15,17}$'
test_strings = ["123456789012345", "1234567890123456", "12345678901234567", "12345678901234", "123456789012345678", "12345678901234a", "12345678901234 "]
for test_string in test_strings:
if re.match(pattern, test_string):
print(f"'{test_string}': 匹配成功")
else:
print(f"'{test_string}': 匹配失败")
const pattern = /^\d{15,17}$/;
const testStrings = ["123456789012345", "1234567890123456", "12345678901234567", "12345678901234", "123456789012345678", "12345678901234a", "12345678901234 "];
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 = "^\\d{15,17}$";
String[] testStrings = {"123456789012345", "1234567890123456", "12345678901234567", "12345678901234", "123456789012345678", "12345678901234a", "12345678901234 "};
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 = @"^\d{15,17}$";
string[] testStrings = {"123456789012345", "1234567890123456", "12345678901234567", "12345678901234", "123456789012345678", "12345678901234a", "12345678901234 "};
foreach (string testString in testStrings) {
if (Regex.IsMatch(testString, pattern)) {
Console.WriteLine($"'{testString}': 匹配成功");
} else {
Console.WriteLine($"'{testString}': 匹配失败");
}
}
}
}
<?php
$pattern = '/^\d{15,17}$/';
$testStrings = ["123456789012345", "1234567890123456", "12345678901234567", "12345678901234", "123456789012345678", "12345678901234a", "12345678901234 "];
foreach ($testStrings as $testString) {
if (preg_match($pattern, $testString)) {
echo "'$testString': 匹配成功\n";
} else {
echo "'$testString': 匹配失败\n";
}
}
?>
pattern = /^\d{15,17}$/
test_strings = ["123456789012345", "1234567890123456", "12345678901234567", "12345678901234", "123456789012345678", "12345678901234a", "12345678901234 "]
test_strings.each do |test_string|
if pattern.match?(test_string)
puts "'#{test_string}': 匹配成功"
else
puts "'#{test_string}': 匹配失败"
end
end