Ignoring the line break in regex?

前端 未结 3 1077
旧巷少年郎
旧巷少年郎 2021-01-13 03:04

I have below content in text file

  some texting content \"\"  Test

I read it from

3条回答
  •  梦谈多话
    2021-01-13 03:48

    If you want your dot (.) to match newline also, you can use Pattern.DOTALL flag. Alternativey, in case of String.replaceAll(), you can add a (?s) at the start of the pattern, which is equivalent to this flag.

    From the Pattern.DOTALL - JavaDoc : -

    Dotall mode can also be enabled via the embedded flag expression (?s). (The s is a mnemonic for "single-line" mode, which is what this is called in Perl.)

    So, you can modify your pattern like this: -

    expectedStr = inputString.replaceAll("(?s)", "Content");
    

    NOTE: - You don't need to escape your angular bracket(<).

提交回复
热议问题