Java中带引号的模式匹配
我想知道如何使用模式来检查正则表达式是否与字符串匹配?我的问题是,我希望引号中的文本像一个单词一样,就像在第二种情况下一样 字符串:Java中带引号的模式匹配,java,regex,string,compare,matching,Java,Regex,String,Compare,Matching,我想知道如何使用模式来检查正则表达式是否与字符串匹配?我的问题是,我希望引号中的文本像一个单词一样,就像在第二种情况下一样 字符串: message "the id of %type of the clicked block% is %id of the clicked block%." send "You are not allowed to use this command." 语法: message .* send .* to .* 应返回: true False 另一种情况
message "the id of %type of the clicked block% is %id of the clicked block%."
send "You are not allowed to use this command."
语法:
message .*
send .* to .*
应返回:
true
False
另一种情况:
字符串:
message "the id of %type of the clicked block% is %id of the clicked block%."
send "You are not allowed to use this command."
语法:
message .*
send .* to .*
应返回:
true
False
如我在上述评论中所述,希望这能回答您的问题,但您可以简单地以引号结束,并在引号之间匹配任何内容,如: 举个例子:
message "the id of %type of the clicked block% is %id of the clicked block%."
send "You are not allowed to use this command."
匹配这两个正则表达式的正则表达式包括使用\.\来匹配由\转义的引号之间的所有内容
因此,在这种情况下,使用send\.\ to将是错误的
介绍比赛小组:
send (\".*\")
您可以使用\来转义引号。然而,您的第二个案例是不正确的,因为它应该是正确的,因为。*包括两件事:1。它与除换行符和2*之外的任何字符匹配,2*与前面标记的0或多个匹配。引号并不能阻止匹配的发生。@signus我只是显示了我想要的内容。您不能让它们作为一个词,但是您可以将引号中的所有内容都设置为匹配组,或者您可以只关注引号内或引号外的匹配数据,例如发送\.*\到。@signus不应该是\.*?\而应该是\[^]\?@GáborBakos不一定是唯一的,因为这是一场懒惰的比赛。尽管包含懒惰量词是完全正确的。