我想用一个单词和一个大文本作为堆栈。我可以做匹配,但我需要它从给定的子字符串中获得尽可能少的额外字符。
我现在使用的模式是'/\b([a-zA-Z0-9]*?'.$substring.'[a-zA-Z0-9]*?)\b/'
,其中$substring
是子字符串变量,我需要[a-zA-Z0-9]
部分尽可能小,我试图用懒惰{{{ 1}}匹配,但我不认为它的工作。
有什么想法吗?
*?
我只需要$substring='object';
preg_match('/\b([a-zA-Z0-9]*?'.$substring.'[a-zA-Z0-9]*?)\b/', 'As a stage on which objects objectified are located and where the dramas of their ', $matches);
而不是'objects'
。有没有比通过数组并在php中检查更好的方法?