我不擅長的正則表達式,我試圖使用java.lang.String
replaceAll()
方法與代碼段如下正則表達式:PatternSyntaxException:非法重複
A爲:
public class method3 {
public static int addTwoNumbers(int one, int two){
return one+two;
}
public static void main (String[] args){
int total = addTwoNumbers(1, 3);
System.out.println(total);
}
}
與乙取代
null
public class method3 {
/* some writting */
public static int addTwoNumbers(int one, int two){
return one+two;
}
/*more text*/
public static void main (String[] args){
int total = addTwoNumbers(1, 3);
System.out.println(total);
}//end of
}
這是給我以下錯誤
java.util.regex.PatternSyntaxException: Illegal repetition
我猜這與/**/
字符有關?
你是如何分類的,還有其他需要注意的角色嗎?
編輯:這是錯誤消息
Exception in thread "AWT-EventQueue-0" java.util.regex.PatternSyntaxException: Illegal repetition near index 25
null
public class method2 {
public static int addTwoNumbers(int one, int two){
return one+two;
}
public static void main (String[] args){
int total = addTwoNumbers(1, 3);
System.out.println(total);
}
}
^
at java.util.regex.Pattern.error(Pattern.java:1924)
at java.util.regex.Pattern.closure(Pattern.java:3104)
at java.util.regex.Pattern.sequence(Pattern.java:2101)
at java.util.regex.Pattern.expr(Pattern.java:1964)
at java.util.regex.Pattern.compile(Pattern.java:1665)
at java.util.regex.Pattern.<init>(Pattern.java:1337)
....
調用的replaceAll()
String a = readFile(directoryToAddFile,startOfCode, endOfCode);
String b = textarea.getText().toString();
String content = IOUtils.toString(new FileInputStream(directoryToAddFile));
content = content.replaceAll(a, b);
IOUtils.write(content, new FileOutputStream(directoryToAddFile));
該代碼片段是不是他們? – RNJ
如果您顯示失敗的代碼,這將有所幫助。是的,'*'在正則表達式中具有特殊含義......但是可能正則表達式不是這裏最好的方法。 –
調用replaceAll在哪裏? – KidTempo