/^thunderx?:\/\/[a-zA-Z\d]+=$/
thunder 后面跟一个可选的 x。即可以匹配 thunder 或 thunderx。
thunder 字符串。x 是可选的,匹配 0 次或 1 次 x。:// 字符串。= 字符。thunder:// 或 thunderx:// 开头,后面跟一个或多个字母或数字字符,并以等号 = 结尾的字符串。"thunder://abc123=""thunderx://A1b2C3=""thunder://XYZ456=""thunderx://789abc=""thunder://abc123"(没有等号 = 结尾)"thunderx://A1b2C3"(没有等号 = 结尾)"thunder:/abc123="(缺少一个斜杠 /)"thunderxx://abc123="(多一个 x)"thunderx://abc 123="(包含空格)"thunderx://abc!123="(包含非法字符 !)import re
pattern = r'^thunderx?:\/\/[a-zA-Z\d]+=$'
test_strings = ["thunder://abc123=", "thunderx://A1b2C3=", "thunder://XYZ456=", "thunderx://789abc=", "thunder://abc123", "thunderx://A1b2C3", "thunder:/abc123=", "thunderxx://abc123=", "thunderx://abc 123=", "thunderx://abc!123="]
for test_string in test_strings:
if re.match(pattern, test_string):
print(f"'{test_string}': 匹配成功")
else:
print(f"'{test_string}': 匹配失败")
const pattern = /^thunderx?:\/\/[a-zA-Z\d]+=$/;
const testStrings = ["thunder://abc123=", "thunderx://A1b2C3=", "thunder://XYZ456=", "thunderx://789abc=", "thunder://abc123", "thunderx://A1b2C3", "thunder:/abc123=", "thunderxx://abc123=", "thunderx://abc 123=", "thunderx://abc!123="];
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 = "^thunderx?:\\/\\/[a-zA-Z\\d]+=$";
String[] testStrings = {"thunder://abc123=", "thunderx://A1b2C3=", "thunder://XYZ456=", "thunderx://789abc=", "thunder://abc123", "thunderx://A1b2C3", "thunder:/abc123=", "thunderxx://abc123=", "thunderx://abc 123=", "thunderx://abc!123="};
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 = @"^thunderx?:\/\/[a-zA-Z\d]+=$";
string[] testStrings = {"thunder://abc123=", "thunderx://A1b2C3=", "thunder://XYZ456=", "thunderx://789abc=", "thunder://abc123", "thunderx://A1b2C3", "thunder:/abc123=", "thunderxx://abc123=", "thunderx://abc 123=", "thunderx://abc!123="};
foreach (string testString in testStrings) {
if (Regex.IsMatch(testString, pattern)) {
Console.WriteLine($"'{testString}': 匹配成功");
} else {
Console.WriteLine($"'{testString}': 匹配失败");
}
}
}
}
<?php
$pattern = '/^thunderx?:\/\/[a-zA-Z\d]+=$/';
$testStrings = ["thunder://abc123=", "thunderx://A1b2C3=", "thunder://XYZ456=", "thunderx://789abc=", "thunder://abc123", "thunderx://A1b2C3", "thunder:/abc123=", "thunderxx://abc123=", "thunderx://abc 123=", "thunderx://abc!123="];
foreach ($testStrings as $testString) {
if (preg_match($pattern, $testString)) {
echo "'$testString': 匹配成功\n";
} else {
echo "'$testString': 匹配失败\n";
}
}
?>
pattern = /^thunderx?:\/\/[a-zA-Z\d]+=$/
test_strings = ["thunder://abc123=", "thunderx://A1b2C3=", "thunder://XYZ456=", "thunderx://789abc=", "thunder://abc123", "thunderx://A1b2C3", "thunder:/abc123=", "thunderxx://abc123=", "thunderx://abc 123=", "thunderx://abc!123="]
test_strings.each do |test_string|
if pattern.match?(test_string)
puts "'#{test_string}': 匹配成功"
else
puts "'#{test_string}': 匹配失败"
end
end