[Solved] Regular Expressions in Java replace odd # of slashes
Pattern p = Pattern.compile(“(?<!/)/(//)*(?!/)”); Matcher m = p.matcher(inputString); String outputStr = m.replaceAll(“$0$0”); (?<!/) makes sure there are no slashes right before the match; /(//)* matches an odd number of slashes; (?!/) makes sure there are no slashes right after the match. The replacement string is $0$0, which doubles up the matched slashes. I’ve tested this … Read more