正则表达式由2个相同长度的数字用短划线分隔 [英] Regex for 2 numbers of the same length separated by dash

查看:105
本文介绍了正则表达式由2个相同长度的数字用短划线分隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

符合以下条件的正确正则表达式是什么:

What's the right regex for matching the following criteria:


  • 两个数字,以短划线( - )
  • $分隔b $ b
  • 这两个数字必须具有相同的位数,但至少为1且不超过5位数

  • 数字之前/之后/之间和短划线可能是任意的空白

  • Two numbers, separated by a dash (-)
  • Both numbers must have the same amount of digits, but at least 1 and not more than 5 digits
  • before/after/between numbers and the dash there may be arbitrary whitespace

匹配的示例:


  • 123-444

  • 1234 - 5678

  • 98-76

不应匹配的示例:


  • 1234-567

  • 123456-789012

这样的事情可能吗?

推荐答案

可能你可以使用这个:

^ *((\d *- *\d)|(\d{2} *- *\d{2})|(\d{3} *- *\d{3})|(\d{4} *- *\d{4})|(\d{5} *- *\d{5})) *$

这篇关于正则表达式由2个相同长度的数字用短划线分隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆