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 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退