Pick longest match always
parent
a4e5f000d5
commit
dc033e33d6
|
@ -164,16 +164,21 @@ class JsonManipulator
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preg_match('{"'.preg_quote($name).'"\s*:}i', $children)) {
|
if (preg_match('{"'.preg_quote($name).'"\s*:}i', $children)) {
|
||||||
if (preg_match('{"'.preg_quote($name).'"\s*:\s*(?:[0-9.]+|null|true|false|"[^"]+"|\{'.self::$RECURSE_BLOCKS.'\})}', $children, $matches)) {
|
if (preg_match_all('{"'.preg_quote($name).'"\s*:\s*(?:[0-9.]+|null|true|false|"[^"]+"|\{'.self::$RECURSE_BLOCKS.'\})}', $children, $matches)) {
|
||||||
$children = preg_replace('{,\s*'.preg_quote($matches[0]).'}i', '', $children, -1, $count);
|
$bestMatch = '';
|
||||||
|
foreach ($matches[0] as $match) {
|
||||||
|
if (strlen($bestMatch) < strlen($match)) {
|
||||||
|
$bestMatch = $match;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$children = preg_replace('{,\s*'.preg_quote($bestMatch).'}i', '', $children, -1, $count);
|
||||||
if (1 !== $count) {
|
if (1 !== $count) {
|
||||||
$children = preg_replace('{'.preg_quote($matches[0]).'\s*,?\s*}i', '', $children, -1, $count);
|
$children = preg_replace('{'.preg_quote($bestMatch).'\s*,?\s*}i', '', $children, -1, $count);
|
||||||
if (1 !== $count) {
|
if (1 !== $count) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!trim($children)) {
|
if (!trim($children)) {
|
||||||
|
|
Loading…
Reference in New Issue