Forward slash in Java Regex

后端 未结 3 1624
甜味超标
甜味超标 2020-12-08 18:24

I can\'t figure out why the following code doesn\'t behave as expected

\"Hello/You/There\".replaceAll(\"/\", \"\\\\/\");
  • Expected out
3条回答
  •  再見小時候
    2020-12-08 19:04

    Double escaping is required when presented as a string.

    Whenever I'm making a new regular expression I do a bunch of tests with online tools, for example: http://www.regexplanet.com/advanced/java/index.html

    That website allows you to enter the regular expression, which it'll escape into a string for you, and you can then test it against different inputs.

提交回复
热议问题