我有字符串作为abvd.qweqw.sdfs.a=aqwrwewrwerrew
. 我需要解析这个字符串并在之前=
和之后得到一块=
。符号.
可以出现多次。那么,请告诉我,我可以使用哪个正则表达式进行解析?谢谢你。
问问题
84 次
3 回答
1
Purely based on your example:
/([a-z.]+)=([a-z]+)/
Edit
But actually:
/([a-z_.]+)=(.*)/i
The results are in memory groups 1 and 2. In code:
if (preg_match('/^([a-z_.]+)=(.*)/i', $str, $matches)) {
// $matches[1] contains part before =
// $matches[2] contains part after =
}
Btw, I've tweaked the expression by anchoring it (using ^
). If that doesn't work, just remove it from the expression.
于 2012-06-19T07:16:14.320 回答
1
You can use simple string function for that.
list($first, $second) = explode('=', 'abvd.qweqw.sdfs.a=aqwrwewrwerrew);
于 2012-06-19T07:16:58.807 回答
0
这就是完整的代码。
<?php
if(preg_match('/([a-z.]+)=([a-z]+)/', "abvd.qweqw.sdfs.a=aqwrwewrwerrew", $matches)){
print $matches[1]."\n";
print $matches[2]."\n";
}
?>
于 2012-06-19T07:37:20.243 回答