Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何检查字符串中的字符重复?_Regex_Regex Negation_Regex Lookarounds_Regex Greedy - Fatal编程技术网

Regex 如何检查字符串中的字符重复?

Regex 如何检查字符串中的字符重复?,regex,regex-negation,regex-lookarounds,regex-greedy,Regex,Regex Negation,Regex Lookarounds,Regex Greedy,大家好,我是正则表达式的新手,我正在尝试为字符串值的模式创建表达式。规则如下 1) String must start with the 'O' or 'T' 2) After that there must be 9 digits 3) After that there must be 'T' 4) After that alphanumeric string with specs and numbers and character'D' these can repeat any numbe

大家好,我是正则表达式的新手,我正在尝试为字符串值的模式创建表达式。规则如下

1) String must start with the 'O' or 'T'
2) After that there must be 9 digits 
3) After that there must be 'T'
4) After that alphanumeric string with specs and numbers and character'D' these can repeat any number of time in string of length 25 
5) Then character 'O'
6) Then string with numbers and spaces of length 5  
然而,我已经完成了所有的条件,但对于条件4,我不知道该如何做,因为它可以在给定的长度为25的字符串中重复“D”任意次数。写现在我已经调整了可选的'D'在每一个地方,它在字符串中,这是一种非常长的正则表达式,所以我希望有人会帮助我与条件4。任何帮助都将是伟大的

要匹配的字符串->

T011600062TO51D45D0399D0O 1807
最新的正则表达式->

(?x)((?:[OT]\d{9})(?:T\s*\d*\s*[0-9DO ]\d*\s*[OD0-9 ]\s*\d*[D0-9]\s*\d*[0-9OD ]\d*)(?:[O]\s*\d*)\b)
我对正则表达式的这一部分感到困惑

(?:T\s*\d*\s*[0-9DO ]\d*\s*[OD0-9 ]\s*\d*[D0-9]\s*\d*[0-9OD ]\d*)

这是正确的方法吗?

条件4不清楚


O|T\d{9}T[d\d]{25}O[\d]{5}

可能是d{0,25}。这意味着D重复了0~25次。

你可以在所有匹配的模式中尝试这个

(O|T)\d{9}T[DO \d]{0,25}O[\d ]{5}

你能发布你最新的正则表达式吗?@Jerry-我已经添加了最新的正则表达式regex@Kriomant-第四个条件-长度为25个或更少字符的字符串,介于“T”和“O”之间,25个或更少字符只能包含数字、空格和任意次数的字符“D”以及一次包含字符“O”