Php 正则表达式匹配出血

Php 正则表达式匹配出血,php,regex,Php,Regex,我有一段文字。我想匹配一个单词,并在它前面选择10个单词,然后在关键字旁边选择10个单词 到目前为止,我已经完成了以下内容,其中选择了前30个字符和后30个字符。如何转换它,以便我可以实际选择前10个单词和后10个单词 .{1,30}?keyword.{1,30} 例如: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's s

我有一段文字。我想匹配一个单词,并在它前面选择10个单词,然后在关键字旁边选择10个单词

到目前为止,我已经完成了以下内容,其中选择了前30个字符和后30个字符。如何转换它,以便我可以实际选择前10个单词和后10个单词

.{1,30}?keyword.{1,30}
例如:

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum
has been the industry's standard dummy text ever since the 1500s, when an unknown printer
took a galley of type and scrambled it to make a type specimen book. It has survived not 
only five centuries, but also the leap into electronic typesetting, remaining essentially
unchanged. It was popularised in the 1960s with the release of Letraset sheets containing
Lorem Ipsum passages, and more recently with desktop publishing software like Aldus
PageMaker including versions of Lorem Ipsum.
我想匹配
标准
。正则表达式应该返回以下匹配项

printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer

也许是这样的

(\w+\s+){1,10}\s*keyword\s*(\w+\s+){1,10}
如果您将“word”定义为“非空白字符字符串”,那么这似乎可以做到:

((\S+\s){,10})(standard)((\s\S+){,10})
演示: