[英]regex for not matching alpha plus numeric range
I have the following regex我有以下正则表达式
.{19}_.{3}PDR_.{8}(ABCD|CTNE|PFRE)006[0-9][0-9].{3}_.{6}\.POC
a match is for example一场比赛是例如
NRM_0157F0680884976_598PDR_T0060000ABCD00619_00_6I1N0T.POC
and would like to negate the (ABCD|CTNE|PFRE)006[0-9][0-9]
portion such that并想否定
(ABCD|CTNE|PFRE)006[0-9][0-9]
部分,使得
NRM_0157F0680884976_598PDR_T0060000ABCD00719_00_6I1N0T.POC
is a match but是一场比赛,但
NRM_0157F0680884976_598PDR_T0060000ABCD007192_00_6I1N0T.POC
or或者
NRM_0157F0680884976_598PDR_T0060000ABCD0061_00_6I1N0T.POC
is not (the negated part must be 9 chars long just like the non negated part for a total length of 58 chars).不是(否定部分必须是 9 个字符长,就像非否定部分一样,总长度为 58 个字符)。
Consider using the following pattern:考虑使用以下模式:
\b(?:ABCD|CTNE|PFRE)006[0-9][0-9]\b
Sample Java code:示例 Java 代码:
String input = "Matching value is ABCD00601 but EFG123 is non matching";
Pattern r = Pattern.compile("\\b(?:ABCD|CTNE|PFRE)006[0-9][0-9]\\b");
Matcher m = r.matcher(input);
while (m.find()) {
System.out.println("Found a match: " + m.group());
}
This prints:这打印:
Found a match: ABCD00601
I would like to propose this expression我想提出这个表达
(ABCD|CTNE|PFRE)006\\d{1,2}
where \\d{1,2}
catches any one or two digit number that is it would get any alphanumeric values from ABCD0060~ABCD00699 or CTNE0060~CTNE00699 or PFRE0060~PFRE00699其中
\\d{1,2}
捕获任何一位或两位数字,它可以从 ABCD0060~ABCD00699 或 CTNE0060~CTNE00699 或 PFRE0060~PFRE00699 中获取任何字母数字值
as user @Hao Wu mentioned the above regex would also accept if its ABCD0060 which is not ideal so this should do the job by removing 1 from the { } we can get正如用户@Hao Wu 提到的,如果它的 ABCD0060 不理想,上面的正则表达式也会接受,所以这应该通过从 {} 中删除 1 来完成我们可以得到的
alphanumeric values from ABCD00600~ABCD00699 or CTNE00600~CTNE00699 or PFRE00600~PFRE00699 so the resulting regex would be来自 ABCD00600~ABCD00699 或 CTNE00600~CTNE00699 或 PFRE00600~PFRE00699 的字母数字值,因此生成的正则表达式为
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.