我正在解析脚本中的错误字符串,并且有一个包含不应该出现在代码行中的字符串的数组列表.
但有些字符串应该在它们不完全是字符串时传递.
例如:
列表包含"foo"和"bar"
文本行:
This is foo
and this is BAR
but not 'foo'
and not 'BAR'
but also not FOO_BAR
but we want FOO%TEXT
and also bar.text
结果
This is foo
and this is BAR
but we want FOO%TEXT
and also bar.text
我已经try 了一个我在网上和Stackoverflow上找到的例子,但这些对我来说不起作用,他们不会过滤引用的例子.
String pattern = ".*\\"+strTables[i]+"\\b.*[^(\\w|')]";
Pattern r = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
Matcher m = r.matcher(line);
if (m.find()) {
System.out.println (strTables[i] + ": " + line);
break;
}