dYou will know after you try it. Error: error: illegal escape character
+: Indicates a match greater than once d+ matches d+匹配 d,...,ddd,...,ddd,... and the like
I didn’t pay attention to this issue before, and then I looked for some information. I also had problems with my original understanding. The answer just now was incomplete
It should be \n 或nBoth are fine
The first one is to directly turn it into n in the regex and be processed by the regex engine n被正则引擎处理 第二种是n被Java直接转化为一个newline character就是'u000A'The second one is to directly convert n into a newline character by Java, which is 'u000A 'Of course regular expressions can also be matched
The last question is to match the literal "\"+"n""\"+"n" 可以在编译正则的时候用Pattern.LITERAL 那样正则引擎就会把n当成和nYou can use Pattern.LITERAL when compiling the regular expression. The engine will treat n as and n instead of matching newline characters. Of course, you should use the first method.
Because your language does not have a regular type, it can only be expressed as a string, so you need to escape it one more time. \n 是正则的 n 匹配换行,n It’s a string change. Of course it’s correct to directly match line breaks
d
You will know after you try it. Error:error: illegal escape character
+: Indicates a match greater than once
d+
matchesd+
匹配d
,...,ddd
,...,ddd
,... and the likeI didn’t pay attention to this issue before, and then I looked for some information. I also had problems with my original understanding. The answer just now was incomplete
It should be
\n
或n
Both are fineThe first one is to directly turn it into
n
in the regex and be processed by the regex enginen
被正则引擎处理第二种是
n
被Java直接转化为一个newline character就是'u000A'
The second one is to directly convertn
into a newline character by Java, which is'u000A '
Of course regular expressions can also be matchedThe last question is to match the literal
"\"
+"n"
"\"
+"n"
可以在编译正则的时候用
Pattern.LITERAL
那样正则引擎就会把n
当成和
n
You can usePattern.LITERAL
when compiling the regular expression. The engine will treatn
asand
n
instead of matching newline characters. Of course, you should use the first method.Because your language does not have a regular type, it can only be expressed as a string, so you need to escape it one more time.
\n
是正则的 n 匹配换行,n
It’s a string change. Of course it’s correct to directly match line breaks