quote_ABC_123123='jsonparse1';
quote_ABC_123123123='jsonparse2';
Regularly obtains the characters after the second _ and the following string to form an array
[123123:jsonparse1,123123123:jsonparse2]
How to implement it with js? = =
PHP中文网2017-06-06 09:56:11
var obj = {};
["quote_ABC_123123='jsonparse1'", "quote_ABC_123123123='jsonparse2'"].forEach(v => {
v.replace(/.*_(\d*)='(.*)'/, (a, b, c) => {
obj[b] = c;
});
})
console.log(obj);
世界只因有你2017-06-06 09:56:11
If the composition format is fixed, it can be like this:
str.split("_")[2];
or lastIndexOf gets the last "_" position and intercepts the following string,
For sure, I’m not very familiar with it, so I just use it and look it up. I’ll add more later downstairs
某草草2017-06-06 09:56:11
In php, the expression "/(1+)='(w+)';$/" can extract the characters on both sides of the equal sign
巴扎黑2017-06-06 09:56:11
Regular php:
preg_match("/quote_ABC_(.+?)='(.+?)'/", "quote_ABC_123123='jsonparse1'", $matches);
var_dump(array($matches[1] => $matches[2]));
explode php:
$arr = explode('_', "quote_ABC_123123='jsonparse1'");
$result = explode('=', $arr[2]);
var_dump(array($result[0] => trim($result[1], "'")));
淡淡烟草味2017-06-06 09:56:11
The answer is already there, I will add it. If the prefix is quote_ABC, it is best to write quote_ABC in the third digit to confirm whether the requirement is just a number
and whether there will be double quotes in the following single quotes. In addition, forEach is an ES5 API