0

我想从以下错误消息中正则表达式第二个'':

Duplicate entry 'this_can_be_anything' for key 'I_want_to_grab_this'

我正在使用 php,但对正则表达式的工作原理非常模糊。或者也许我应该使用其他东西而不是正则表达式?任何方向?泰。

4

2 回答 2

1

直截了当:

preg_match('/Duplicate entry \'.+\' for key \'(.+)\'/', $s, $m);并使用$m[1]

$m

array(2) {
  [0]=>
  string(68) "Duplicate entry 'this_can_be_anything' for key 'I_want_to_grab_this'"
  [1]=>
  string(19) "I_want_to_grab_this"
}
于 2013-02-26T13:49:47.197 回答
0

这应该有效:

$yourstring = 'Duplicate entry...';
if (preg_match("=^[^']*'[^']*'[^']*'([^']*)'=", $yourstring, $matches)) {
    echo "Found value: " . $matches[1];
}

但是,这将匹配具有以下格式的任何行:

Something 'something' something 'something'

不确定你是否想要那个。如果没有,请按照k102 的答案

于 2013-02-26T13:50:07.213 回答