验证场结构的正则表达

发布于 2025-01-21 09:23:03 字数 193 浏览 5 评论 0原文

我想在Linux中实现一个正则表达式,该表达式使用GREP允许我验证一个字段包含15个数值,并且占据第五位置的值(从左开始)是5或6。

我已经达到了点但是,确定其最多包含15个值的要求,我找不到占据第五位置的一个值是5或6。这是:

grep -E "^[0-9]{1,15}"

有什么想法吗?

I would like to implement a regular expression in linux that using grep allows me to verify that a field contains 15 numerical values and that the value occupying the fifth position (starting from left) is either a 5 or a 6.

I have reached the point of defining the requirement that it contains a maximum of 15 values, however, I can not get that the one that occupies the fifth position is a 5 or 6. It would be:

grep -E "^[0-9]{1,15}"

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彻夜缠绵 2025-01-28 09:23:03

对于正好的15个数字,5个位置为5或6:

grep -E "^[0-9]{4}[56][0-9]{10}$"
  • ^ String的启动
  • [0-9] {4}匹配4位数字
  • [56]匹配56
  • [0-9] {10}匹配10位数字
  • $结束of string

To match at least the first 5 characters followed by 0-10 digits after it, and allow a partial match like matching 123462222233333 in 12346222223333344444

grep -Eo "^[0-9]{4}[56][0-9]{0,10}"

For exactly 15 numbers, and the 5 position is either 5 or 6:

grep -E "^[0-9]{4}[56][0-9]{10}
quot;
  • ^ Start of string
  • [0-9]{4} Match 4 digits
  • [56] Match either 5 or 6
  • [0-9]{10} Match 10 digits
  • $ End of string

To match at least the first 5 characters followed by 0-10 digits after it, and allow a partial match like matching 123462222233333 in 12346222223333344444

grep -Eo "^[0-9]{4}[56][0-9]{0,10}"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文