dprxj1995 2015-11-08 14:05
浏览 16
已采纳

PHP的正则表达式:匹配一组引号中的字符[重复]

This question already has an answer here:

<input name="so and so" id="john doe" value="something something" />

I want to match only the space character that is within the " of a value= attribute.

I came up with this:

value="[^"',:<>/
]*[ ][^"',:<>/
]*"

Problem is this matches the whole string, where I just need the space in the matched string from above.

I am reading some tutorials, which leads me to think I need to use a conditional statement, but I can't seem to figure out how that would work. My guess (which of course didn't work) was:

(?(?=value="[^"',:<>/
]*[^"',:<>/
]*")[ ])

Any help is appreciated. Thanks!

</div>
  • 写回答

1条回答 默认 最新

  • douxing5199 2015-11-08 14:11
    关注
    \bvalue="\K|\G(?!^)[^"]*?\K\s+
    

    You can use this to find spaces which are in value=" and before closing ".See demo.

    https://regex101.com/r/lR1eC9/11

    EDIT:

    (?:(?<=\bvalue=")|\G(?!^))[^"]*?\K\s+(?=[^"=]*")
    

    See demo.

    https://regex101.com/r/lR1eC9/13

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?