开发者

How to match words with common prefix in PHP?

I need to write a 开发者_StackOverflow中文版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.


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


I think this gets you there:

/\<word(|s|ing)\>/


\b(accounting|accounts|account)\b


I might be wrong, but I don't think "/\b*word*\b/" gets word, instead it actually matches things like '''''wor' or ||worddddd|, if you want word and its variant, try:

/\bword[^\b]+\b/i
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜