正则表达式pattern内部\\\\用法

来源:互联网 发布:硬盘修复软件 编辑:程序博客网 时间:2024/06/14 19:45

Pattern pattern = Pattern.compile("(http://|https://){1}-[\\w\\.\\\\\\-/:]+");

Matcher matcher = pattern.matcher("dsdsds<http://-dsds//gfgffd\\-:fd>fdf");


以上pattern 里面 :

\\w → \w  匹配字符

\\. → \.   匹配.

\\\\  → \\ 匹配反斜杠  尤其注意

\\-  → \- 匹配 - , 此处由于-位于[  ] 内,所以需要转义; 而注意在pattern中[  ]外边的- 则不需要转义


输出为:

http://-dsds//gfgffd\-:fd

原创粉丝点击