dongqiao6445 2015-01-10 04:08
浏览 43

您好,请帮我纠正我的正则表达式以检测数字

[a-z\%\/\-\(\)\s]?\d{3}[a-z\%\/\-\(\)\s]?\d{3}[a-z\%\/\-\(\)\s]?\d{4}[a-z\%\/\-\(\)\s]?

My above regex is what I've come up with. But I need something that can detect a few more patterns of numbers, and then, once the numbers are matched, remove all other texts, letters, chars in the line but the numbers. below is my regex.

I really need help with this been looking forever.

https://www.regex101.com/r/hT5eD9/1

FIXED

  • 写回答

3条回答 默认 最新

  • douji4223 2015-01-10 04:18
    关注

    You can take this approach:

    Match 1 or more non-digits that are followed by digits on either side to detect non-digits in between digits and remove them.

    Using this regex:

    (?<=\d)[^\d
    ]+(?=\d)
    

    RegEx Demo

    Code:

    $result = preg_replace("~(?<=\\d)[^\\d\
    ]+(?=\\d)~", '', $input);
    
    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥15 对于这个问题的算法代码
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题