【发布时间】:2013-07-23 23:29:13
【问题描述】:
我已经从这个答案中获取了匹配斜杠和反斜杠的正则表达式:Regex to match both slash in JAVA
String path = "C:\\system/properties\\\\all//";
String replaced = path.replaceAll("[/\\\\]+",
System.getProperty("file.separator"));
但是,我得到了错误:
线程“主”java.lang.StringIndexOutOfBoundsException 中的异常: 字符串索引超出范围:1
这个正则表达式有什么问题?删除+ 不会改变任何东西,错误信息是一样的...
【问题讨论】:
-
你可以在这里使用
Path类吗?它只在 java 7 中可用,只是让你意识到它的存在。 -
replace()vsreplaceAll()!!!!