[英]Regex for case sensitive and conditions for the matching
I am trying to match words with the following structure:我正在尝试匹配具有以下结构的单词:
call NAME, or call name; call NAME, 或 call name; that is, preceded by "call" and a blank space
也就是说,前面是“呼叫”和一个空格
And和
NAME (whatever; that is, NAME+ blank space+( and the same for the lower case NAME(随便什么;即 NAME+ 空格+(,小写的也一样
I learnt (?.) for case insensitiveness.我学会了 (?.) 不区分大小写。 How the complete regex command would be?
完整的正则表达式命令如何?
This does the trick:这是诀窍:
Pattern pattern = Pattern.compile("(?:call (?i)name)|(?:(?i)name \\(.*)");
System.out.println(pattern.matcher("call NAME").matches());
System.out.println(pattern.matcher("call name").matches());
System.out.println(pattern.matcher("CALL name").matches());
System.out.println(pattern.matcher("NAME (blablabla").matches());
System.out.println(pattern.matcher("name (blablabla").matches());
Output:输出:
true
true
false
true
true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.