PHP正则表达式属性从字符串



我有一个这样的字符串:

family="ABeeZee;100regular" decoration="" style="normal" txtalign="txt-left" size="14px" line="22px" padding="0px" bold="" uppercase="" color=""" 

我想要得到family:

里面的值/字符串
 ABeeZee;100regular

我知道我需要使用正则表达式,但我仍然不明白如何编写模式…

I try this without success:

$mystring = 'family="ABeeZee;100regular" decoration="" style="normal" txtalign="txt-left" size="14px" line="22px" padding="0px" bold="" uppercase="" color=""" '
$pattern  = '/(family)="(['"])?((?(1).+?|[^s>]+))(?(1)1)"/is';
$string   = preg_replace($pattern, "", $mystring);

使用preg_match()代替preg_replace()来获取值

你只有一个模式,所以你不需要在这里使用条件正则表达式。

preg_match('/family="([^"]+)"/', $mystring, $match);
echo $match[1]; //=> "ABeeZee;100regular"

最新更新