我需要提取一段字符串。我必须从system.cpu.util[,idle]
或net.if.out[eth2]
分别提取idle
和eth2
。使用正则表达式从字符串中提取
我不知道如何检测纠正[
和]
有人可以帮我吗?
我需要提取一段字符串。我必须从system.cpu.util[,idle]
或net.if.out[eth2]
分别提取idle
和eth2
。使用正则表达式从字符串中提取
我不知道如何检测纠正[
和]
有人可以帮我吗?
由于[和]是指在正则表达式中特殊的东西,所以必须在它们前面放一个\,否则preg_match将不会从字面上理解它们。与你的点相同。
一个正则表达式像'preg_match('。* \ [\?P
也不是:preg_match('\。* \ [\?P
@ Leitoo0:您需要分隔符:'preg_match('/ 。* \ [\(?P
这应该工作
preg_match('/\[,?(.*?)\]/', $test, $matches);
这里是preg_match
var= net.if.out[eth2]
preg_match('/\[,?(.*?)\]/', $var, $match);
print match[1];
手动你需要逃避[和],因为它们是元字符使用\\和\\] – RMcLeod 2013-05-02 14:13:27