任何简单的 unicode 字符串都使用以下模式在 c# 正则表达式中类似زسس
或یسیتنانت
匹配,但它们在 java 中不匹配。
谁能解释一下?如何更正它以使其在 Java 中工作?
"\\b[\\w\\p{M}\\u200B\\u200C\\u00AC\\u001F\\u200D\\u200E\\u200F]+\\b"
c# 代码:(它匹配字符串)
private static readonly Regex s_regexEngine;
private static readonly string s_wordPattern = @"\b[\w\p{M}\u200B\u200C\u00AC\u001F\u200D\u200E\u200F]+\b";
static PersianWordTokenizer()
{
s_regexEngine = new Regex(s_wordPattern, RegexOptions.Multiline);
}
public static List<string> Tokenize(string text, bool removeSeparators, bool standardized)
{
List<string> tokens = new List<string>();
int strIndex = 0;
foreach (Match match in s_regexEngine.Matches(text))
{
//Enter in this block
}
java代码:(它不匹配字符串)
private static final String s_wordPattern = "\\b[\\w\\p{M}\\u200B\\u200C\\u00AC\\u001F\\u200D\\u200E\\u200F]+\\b";
static
{
s_regexpattern = Pattern.compile(Pattern.quote(s_wordPattern));
}
public static java.util.ArrayList<String> Tokenize(String text, boolean removeSeparators, boolean standardized)
{
java.util.ArrayList<String> tokens = new java.util.ArrayList<String>();
int strIndex = 0;
s_regexEngine=s_regexpattern.matcher(text);
while(s_regexEngine.find())
{
// it dosnt enter in this block
}