替换" \ + anyChar"使用REGEX的另一个字符串

时间:2015-09-23 06:16:46

标签: java regex string

我正在编写一个java应用程序,它找到包含反斜杠后跟任何字符的字符串的所有部分" \ + anyChar"用另一个字符串。我正在尝试使用正则表达式模式" \。"寻找一个反斜杠,然后是anyChar,但它确实在寻找"。"。我可以用什么模式来反斜杠+ anyChar?

以下是我尝试运行的代码:

public static void main(String[] args) throws IOException 
{
  String input = GetInput();
  String regex = "\\.";
  String replacement = "[ ]"
  String result = input.replaceAll(regex, replacement);

  System.out.println("input:  " + input);
  System.out.println("result: " + result);
}

当我运行此代码时,我得到以下控制台

input:  this is some stuff and then should switch out this\stuff
result: this is some stuff and then should switch out this\stuff

为什么我的正则表达式模式没有检测到" \ s"在这个例子中?

0 个答案:

没有答案