Raw Strings in Java - for regex in particular. Multiline strings

前端 未结 12 1238
青春惊慌失措
青春惊慌失措 2020-12-01 02:13

Is there any way to use raw strings in Java (without escape sequences)?

(I\'m writing a fair amount of regex code and raw strings would make my code immensely more r

12条回答
  •  春和景丽
    2020-12-01 02:16

    I use Pattern.quote. And it solves the problem of the question. Thusly:

    Pattern pattern = Pattern.compile(Pattern.quote("\r\n?|\n"));
    

    The quote method returns a string that would match the provided string argument, which the return string is the properly quoted string for our case.

提交回复
热议问题