简体   繁体   English

PHP正则表达式,以匹配空间和点之间的第一个单词

[英]php regular expression to match first word between space and point

I have a string. 我有一个字符串。 there I need get a one word. 我需要说一个字。 this word is between space and point. 这个词在空间和点之间。 for example 例如

' 'word.

if it find many same pattern words, I need only first word. 如果找到许多相同的模式字,我只需要第一个字。

As far as i understand, you could try : 据我了解,您可以尝试:

/\s(\w+)\./

preg_match('/\s(\w+)\./', 'abc. def. ghi.', $m);
echo $m[1],"\n";

output: 输出:

def

您也可以使用T-Regx

echo pattern(' \w+\.')->match($yourString)->first();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM