简体   繁体   English

正则表达式Javascript匹配字母,除了一个

[英]Regular expression Javascript match letters except one

I am trying to improve my regular expression in order to not match this string when it has a D in it: 我试图改善我的正则表达式,以便在其中包含D时不匹配此字符串:

www.google.com/.../DE69619938D1?cl=e

My regex : 我的正则表达式:

(DE)([0-9]{1,12})((?:[ABCUT][0-9]?)?)
  1. I want to match when "D1" is missing: that's why I put a ? 我想在缺少“ D1”时进行匹配:这就是为什么我放一个? after this group. 在这个小组之后。 (working) (工作中)
  2. I want to match when the letter is ABCU or T. (working) 我想匹配字母为ABCU或T的字母(有效)
  3. But when it is a D after the numbers I don't want to match the string and I don't know how to make this without losing the first rule. 但是当数字后面是D时,我不想匹配字符串,而且我不知道如何在不丢失第一个规则的情况下进行匹配。

尝试这个

(DE)([0-9]{1,12})(?:(?:[ABCUT][0-9]?)|\?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM