douqie6454 2010-12-03 06:32
浏览 96
已采纳

如何在PHP中匹配具有公共前缀的单词?

I need to write a regex to match the word. To find exact word can be done using /\bword\b/ pattern.

But I want the pattern to find word, words, wording and so on.

for example i want to write a pattern to find terms account, accounting, accounts and accountant in a paragraph string.

  • 写回答

4条回答 默认 最新

  • dongxian6653 2010-12-03 06:42
    关注

    To just match your keyword optionally followed by s, ing, ant, you can use:

    /\b($word(?:|s|ing|ant))\b/i
    

    see it

    If you want to allow any optional letters as suffix you can use:

    /\b($word\w*)\b/i
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

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