Java通过编译带有标志的Pattern将regex与自定义行为一起使用
示例
阿Pattern可以用标志进行编译,如果正则表达式被用作文字String,使用内联改性剂:
Pattern pattern = Pattern.compile("foo.",Pattern.CASE_INSENSITIVE| Pattern.DOTALL);
pattern.matcher("FOO\n").matches(); //是真的。
/* Had the regex not been compiled case insensitively and singlelined,
* it would fail because FOO does not match /foo/ and \n (newline)
* does not match /./.
*/
Pattern anotherPattern = Pattern.compile("(?si)foo");
anotherPattern.matcher("FOO\n").matches(); //是真的。
"foOt".replaceAll("(?si)foo", "ca"); // Returns "cat".
热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短