我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

PHP preg_match()找不到匹配项

I need to get the dates matching the format 'dd/mm', but it doesn't seem to work :

$r = 'D 07/11 A 17/11';
$pattern = '/^(0[1-9]|[12][0-9]|3[01])[-\/](0[1-9]|1[012])/';

if(preg_match($pattern, $r, $matches)) {
    print_r($matches);
}

The regex seems to be valid,i've tested it using https://regex101.com/.

You use ^ repexp character. It means: (0[1-9]|[12][0-9]|3[01])[-\/](0[1-9]|1[012]) must to be in the begining of string. Your regex will be valid on:

$r='07/11 A 17/11';

So, remove ^ character.

近期文章

  • 无法在jquery中提交表单
  • Php,Oracle包和NLS设置
  • IPage服务器端问题阻止PHP.ini更新/ PHP显示
  • 致命错误:在magento中的非对象上调用成员函数getMethodInstance()
  • 使用Web浏览器下载文件的PHP脚本
  • 在PHP中加密字符串,其中输出是URL安全的
  • PHP内置的网络服务器根据访问地址提供不同的网页?
  • 比较两个数组并过滤掉哪些数据和哪些数据可用
  • PHP将一些数组键转换为字符串,一些作为整数,我需要一种类型
  • zf2 phpunit scheme routes
  • 通过Office365使用CI3发送电子邮件时出错 - SSL操作失败,代码为1
  • 删除选择的图像
  • Symfony DataTables [Js]作曲家
  • PHP提取youtube在线聊天
  • 检查用户是否已登录并且与配置文件管理中的名称相同
  • PHP值不使用AJAX Post更新
  • Paypal付款后上传到Dropbox
  • 在PHP中过滤多维输入
  • 在Virtuoso Server上设置PHP的问题
  • 雄辩的渴望加载和急切的节省

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华