简体   繁体   English

Java代码中的正则表达式代码

[英]Regex code in java code

I have the following Regex: [<>\\\\]|\\p{C} 我有以下正则表达式: [<>\\\\]|\\p{C}

How can I create as String with that in Java, the problem is in the Regex are two backslashes: 如何使用Java中的String创建字符串,问题在于Regex有两个反斜杠:

String reg="[<>\\]|\p{C}";   // this gets error  

Pattern p = Pattern.compile(reg);

只需使用反斜杠转义反斜杠即可:

String reg="[<>\\\\]|\\p{C}";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM