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

RegEx不能很好地识别十进制数

I am trying to obtain a number with a decimal point using regex, i have this string where the number in question is

RewriteRule ^additem/[0-9]+(\.[0-9]{1,2})?$additem.php?price=$1

However if I enter 2.02, the stored variable is .02. What am I doing wrong?

You need to add a space between the pattern and the replacement, and use a capturing group around the whole float value pattern:

RewriteRule ^additem/([0-9]+(?:\.[0-9]{1,2})?)$ additem.php?price=$1
                     ^       ^^            ^^^    

See the regex demo

近期文章

  • 如何将数组与子元素合并
  • Codeigniter在线访客我可以看到怎么样? [关闭]
  • Symfony / Twig:表单小部件的内部ID?
  • 将Start_date与SQL中的当前日期进行比较
  • GAE IN List查询使用quercus php - 如何?
  • 我无法使用Laravel和VueJs更新数据
  • 在promise axios.all中找不到数据
  • 在函数中找不到PHP全局变量[重复]
  • PHP正则表达式找到特定的阿拉伯语关键字
  • php中的echo和print_r之间​​的区别? [重复]
  • 如何在PHP中使用变量作为字符串?
  • php提取英国邮政编码并验证它
  • 更好的缓存Web服务响应的方法
  • 使用php中的imagefilter()使图像清晰
  • 软件安装过程中的问题
  • VS2008连接SQL2008数据库时出现问题
  • idea可以只添加一次jar包让所有项目包括新项目都可以用吗?
  • 使用torch.tensor时报错
  • 关于shared_from_this()的疑问
  • springboot+shiro认证成功后无法跳转successUrl

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华