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条)

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 R语言 拟时序分析降维图如何减少分支
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统