[\\s].(?i)[snd]
这在你的正则表达式保证一定有一个当前字符其间的空间和n
(后面跟着零或更多空格加上(
符号)。但实际上并没有一个角色。所以你的正则表达式失败并且返回原始字符串而不做任何替换。
String depends2 = "success(job1) AND n(job2)";
depends2 = depends2.replaceAll("\\s(?i)[snd]\\s*\\(", "");
System.out.println(depends2);
输出:
success(job1) ANDjob2)
说明:
\s whitespace (\n, \r, \t, \f, and " ")
(?i) set flags for this block (case-
insensitive) (with^and $ matching
normally) (with . not matching \n)
(matching whitespace and # normally)
[snd] any character of: 's', 'n', 'd'
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times)
\( '('
你是对的,当然 - 我的坏我做了一个错字。我正在寻找[\ s。](?i)[snd] [\ s] * \(意思是至少有一个空格,我把它放在外面:) – Achow 2014-10-18 05:25:06