今天没事看了下正则,随便抓了一段数据,想联系用正则提取
"scoreFlag": 1,
"scoreWeight": 1,
"score": 1.3,
"limitTime": 2000,
"testsNum": 100,
"gateContitionValue": "d15a105a-ccbd-462c-aa61-f9c8858a6224",
"testsType": 1,
"passContitionRequest": 2,
"passContitionValue": "90",
"state": 0,
"gateRepeat": 0,
"gateRepeatMarkWeight": 0.2,
"passFailureMarkWeight": 0.2,
"gateSuperId": "d15a105a-ccbd-462c-aa61-f9c8858a6224",
"mark": "",
"answerWrongFlag": 0,
"courseInfoIds": "",
"rushState": 2,
"crtUser": "admin001",
"crtTime": "2020-07-26 10:10:02",
"crtIp": "192.168.13.48",
"updTime": "2020-07-26 10:10:01",
"id": "e562edd3-49d6-459f-ab43-62e06551509b"
}
{
"scoreFlag": 1,
"scoreWeight": 1,
"score": 1.3,
"limitTime": 2000,
"testsNum": 100,
"gateContitionValue": "d15a105a-ccbd-462c-aa61-f9c8858a6224",
"testsType": 1,
"passContitionRequest": 2,
"passContitionValue": "90",
"state": 0,
"gateRepeat": 0,
"gateRepeatMarkWeight": 0.2,
"passFailureMarkWeight": 0.2,
"gateSuperId": "d15a105a-ccbd-462c-aa61-f9c8858a6224",
"mark": "",
"answerWrongFlag": 0,
"courseInfoIds": "",
"rushState": 2,
"crtUser": "admin001",
"crtTime": "2020-07-26 10:10:02",
"crtIp": "192.168.13.48",
"updTime": "2020-07-26 10:10:01",
"id": "e562edd3-49d6-459f-ab43-62e06551509b"
}
{
"scoreFlag": 1,
"scoreWeight": 1,
"score": 1.3,
"limitTime": 2000,
"testsNum": 100,
"gateContitionValue": "d15a105a-ccbd-462c-aa61-f9c8858a6224",
"testsType": 1,
"passContitionRequest": 2,
"passContitionValue": "90",
"state": 0,
"gateRepeat": 0,
"gateRepeatMarkWeight": 0.2,
"passFailureMarkWeight": 0.2,
"gateSuperId": "d15a105a-ccbd-462c-aa61-f9c8858a6224",
"mark": "",
"answerWrongFlag": 0,
"courseInfoIds": "",
"rushState": 2,
"crtUser": "admin001",
"crtTime": "2020-07-26 10:10:02",
"crtIp": "192.168.13.48",
"updTime": "2020-07-26 10:10:01",
"id": "e562edd3-49d6-459f-ab43-62e06551509b"
}
目标是提取到id:后面双引号里面的内容。
我用一下只能匹配到id一行的内容。不能一次得到里面的内容。
"id": "(.*)"
特来问问大佬们怎么提的
小米8(白)
@HongKongDoll,是呀,用正则匹配。json提取我能提出来。只是想学明白正则方法。干扰太多。总时提不全
小米8(白)
<?php
date_default_timezone_set('Asia/Shanghai');
$str = '
"scoreFlag": 1,
"scoreWeight": 1,
"score": 1.3,
"limitTime": 2000,
"testsNum": 100,
"gateContitionValue": "d15a105a-ccbd-462c-aa61-f9c8858a6224",
"testsType": 1,
"passContitionRequest": 2,
"passContitionValue": "90",
"state": 0,
"gateRepeat": 0,
"gateRepeatMarkWeight": 0.2,
"passFailureMarkWeight": 0.2,
"gateSuperId": "d15a105a-ccbd-462c-aa61-f9c8858a6224",
"mark": "",
"answerWrongFlag": 0,
"courseInfoIds": "",
"rushState": 2,
"crtUser": "admin001",
"crtTime": "2020-07-26 10:10:02",
"crtIp": "192.168.13.48",
"updTime": "2020-07-26 10:10:01",
"id": "e562edd3-49d6-459f-ab43-62e06551509b"
}
{
"scoreFlag": 1,
"scoreWeight": 1,
"score": 1.3,
"limitTime": 2000,
"testsNum": 100,
"gateContitionValue": "d15a105a-ccbd-462c-aa61-f9c8858a6224",
"testsType": 1,
"passContitionRequest": 2,
"passContitionValue": "90",
"state": 0,
"gateRepeat": 0,
"gateRepeatMarkWeight": 0.2,
"passFailureMarkWeight": 0.2,
"gateSuperId": "d15a105a-ccbd-462c-aa61-f9c8858a6224",
"mark": "",
"answerWrongFlag": 0,
"courseInfoIds": "",
"rushState": 2,
"crtUser": "admin001",
"crtTime": "2020-07-26 10:10:02",
"crtIp": "192.168.13.48",
"updTime": "2020-07-26 10:10:01",
"id": "e562edd3-49d6-459f-ab43-62e06551509b"
}
{
"scoreFlag": 1,
"scoreWeight": 1,
"score": 1.3,
"limitTime": 2000,
"testsNum": 100,
"gateContitionValue": "d15a105a-ccbd-462c-aa61-f9c8858a6224",
"testsType": 1,
"passContitionRequest": 2,
"passContitionValue": "90",
"state": 0,
"gateRepeat": 0,
"gateRepeatMarkWeight": 0.2,
"passFailureMarkWeight": 0.2,
"gateSuperId": "d15a105a-ccbd-462c-aa61-f9c8858a6224",
"mark": "",
"answerWrongFlag": 0,
"courseInfoIds": "",
"rushState": 2,
"crtUser": "admin001",
"crtTime": "2020-07-26 10:10:02",
"crtIp": "192.168.13.48",
"updTime": "2020-07-26 10:10:01",
"id": "e562edd3-49d6-459f-ab43-62e06551509b"
}
';
preg_match_all('/"id":."(.*)?"/',$str,$arr);
var_dump($arr);
array(2) {
[0]=>
array(3) {
[0]=>
string(44) ""id": "e562edd3-49d6-459f-ab43-62e06551509b""
[1]=>
string(44) ""id": "e562edd3-49d6-459f-ab43-62e06551509b""
[2]=>
string(44) ""id": "e562edd3-49d6-459f-ab43-62e06551509b""
}
[1]=>
array(3) {
[0]=>
string(36) "e562edd3-49d6-459f-ab43-62e06551509b"
[1]=>
string(36) "e562edd3-49d6-459f-ab43-62e06551509b"
[2]=>
string(36) "e562edd3-49d6-459f-ab43-62e06551509b"
}
}
https://www.php.net/manual/zh/reference.pcre.pattern.syntax.php
点击目录链接查看内容。下方出现的英文是用户评论,不是内容。
这不是json么

小米8高配版(五颜六色)