/**
* 將表達式中‘)...]’替換爲)]
*/public class regex {
public static void main(String[] args) {
String str = "[((A<300)&&(A>200))>0.3]||{[((B<400)&&(B>300))>0.5]&&[((C<400)&&(C>300))>0.5]}";
String newStr = str.replaceAll("\\).+?\\]",")]");
System.out.println(newStr);
}}
在java中的正則表達式使用'\\'來進行轉義,比如要匹配'('這要寫成'\\(',
而在標準正則表達式中使用'\'來轉義,比如要匹配'('這要寫成'\(',
輸出:
[((A<300)]||{[((B<400)]&&[((C<400)]}