我有两个单独的字符串“TM_TASK”和“TM_CHECKLIST”。如何在java中使用正则表达式验证整个单词? 如何在java中使用正则表达式中的AND运算符?我需要验证两个字符串,而不是其中任何一个。我是regex的新手。
@Pattern(value = "(?=.*TM_TASK)(?=.*TM_CHECKLIST).*", patternType = PatternType.REGEX)
@ApiOperation(value = "Fetch all instances of a specific checklist", produces = "application/json", response = ChecklistInstance.class, tags = "tasks")
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "Authorization token", required = true, dataType = "string", paramType = "header"),
@ApiImplicitParam(name = "body", value = "json document", required = true, dataType = "json", paramType = "body") })
@BodyParser.Of(BodyParser.Json.class)
public Result getChecklistInstances() {
答案 0 :(得分:1)
你可以使用正则表达式
(?=.*TM_TASK)(?=.*TM_CHECKLIST).*
如果字符串包含TM_TASK和TM_CHECKLIST,则匹配,请参阅regex101 demo。完成后,您可以使用正则表达式匹配这些单词
TM_(?:TASK|CHECKLIST)
答案 1 :(得分:0)