[英]Regex parse group of numbers
我有的:
1. 25686-47362-04822-08149-48999-28161-15124-63556
2. 25686-47362-04822-08149-48999-28161-15124-6355654534
3. 54354325686-47362-04822-08149-48999-28161-15124-63556
4. 25686-47362-04822-08149-48999-28161-15124-6355654534fds
5. fdsfds54354325686-47362-04822-08149-48999-28161-15124-63556
6. 25686-47362-04822-08149-48999-28161-15124-63556-63556
我期望得到什么
1. 25686-47362-04822-08149-48999-28161-15124-63556
我尝试了最近的([0-9]{5,5}){8}
我试图避免2,3,4,5,6。
尝试这个
string source = @"25686-47362-04822-08149-48999-28161-15124-63556";
bool result = Regex.IsMatch(source, "^[0-9]{5}(-[0-9]{5}){7}$");
说明:
^ anchor (beginning of the string)
[0-9]{5} 5 digits group
(-[0-9]{5}){7} 7 more groups of 5 digits
$ anchor (ending of the string)
我不确定是否有办法要求它“重复”分组,但是我会这样输入:
/^([0-9]{5}\-[0-9]{5}\-[0-9]{5}\-[0-9]{5}\-[0-9]{5}\-[0-9]{5}\-[0-9]{5}\-[0-9]{5})/
您可以使用此:
^\d+\.\s(\d{5}-?){8}$
它与符合您条件的整行匹配:一个数字或更多,一个点,一个空格,8个字符段和带有连字符的5位数字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.