[\u200B\u200C\u200D\u00A0]
\u200B
\u200C
\u200D
\u00A0
[\u200B\u200C\u200D\u00A0]
:匹配任意一个零宽字符。import re
# 零宽字符模式
pattern = r'[\u200B\u200C\u200D\u00A0]'
test_string = "Hello\u200BWorld"
matches = re.findall(pattern, test_string)
if matches:
print("匹配成功: 零宽字符存在")
else:
print("匹配失败: 没有零宽字符")
const pattern = /[\u200B\u200C\u200D\u00A0]/;
const testString = "Hello\u200BWorld";
if (pattern.test(testString)) {
console.log("匹配成功: 零宽字符存在");
} else {
console.log("匹配失败: 没有零宽字符");
}
import java.util.regex.*;
public class RegexTest {
public static void main(String[] args) {
String pattern = "[\\u200B\\u200C\\u200D\\u00A0]";
String testString = "Hello\u200BWorld";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(testString);
if (m.find()) {
System.out.println("匹配成功: 零宽字符存在");
} else {
System.out.println("匹配失败: 没有零宽字符");
}
}
}
using System;
using System.Text.RegularExpressions;
class Program {
static void Main() {
string pattern = "[\u200B\u200C\u200D\u00A0]";
string testString = "Hello\u200BWorld";
if (Regex.IsMatch(testString, pattern)) {
Console.WriteLine("匹配成功: 零宽字符存在");
} else {
Console.WriteLine("匹配失败: 没有零宽字符");
}
}
}
<?php
$pattern = '/[\x{200B}\x{200C}\x{200D}\x{00A0}]/u';
$testString = "Hello\u{200B}World";
if (preg_match($pattern, $testString)) {
echo "匹配成功: 零宽字符存在\n";
} else {
echo "匹配失败: 没有零宽字符\n";
}
?>
pattern = /[\u200B\u200C\u200D\u00A0]/
test_string = "Hello\u200BWorld"
if pattern.match?(test_string)
puts "匹配成功: 零宽字符存在"
else
puts "匹配失败: 没有零宽字符"
end