我想获取单个字符串之间的内容,但是,如果内容为空,则我的正则表达式失败...
<?PHP
$string = "
blaat = 'Some string with an escaped \' quote'; // some comment.
empty1 = ''; // omg! an empty string!
empty2 = ''; // omg! an empty string!
";
preg_match_all( '/(?<not>\'.*?[^\\\]\')/ims', $string, $match );
echo '<pre>';
print_r( $match['not'] );
echo '</pre>';
?>
这将作为输出:
Array
(
[0] => 'Some string with an escaped \' quote'
[1] => ''; // omg! an empty string!
empty2 = '
)
我知道这个问题可以用下面的正则表达式来解决,我想我正在寻找一个真正的解决方案,而不是为每个异常提供修复......
preg_match_all( '/((\'\')|(?<not>\'(.*?[^\\\])?\'))/ims', $string, $match );