doupo5861 2016-09-01 05:07
浏览 17
已采纳

PHP正则表达式任何数字

I search for patterns like this number+space+number+space+anything

If have this right now:

if( preg_match( '[0-9][ ][0-9][ ].', $searchString ) )

This seems to work ok but fails on the numbers. As far as i can see there should be a selector for "any number". How can i do this in regex.

It should return true for these cases:

0 0 asdf
1 0 asdf
0 30 adsf asdf
22 0 a
...
  • 写回答

3条回答 默认 最新

  • doumengxue7371 2016-09-01 05:12
    关注

    [0-9] only accepts the integers 0,1,2,3,4,5,6,7,8,9. For any integer, you need to allow one or more repetitions of [0-9]. If you use the shortcut \d for [0-9] then you can write it as

    \d+ \d+ .*

    The + symbol means One or more repetitions.

    Note: It seems like your new to reg expression. Try out this free regex tutorial.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计