Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正则表达式:在php中需要_Php_Regex Negation_Regex Lookarounds - Fatal编程技术网

正则表达式:在php中需要

正则表达式:在php中需要,php,regex-negation,regex-lookarounds,Php,Regex Negation,Regex Lookarounds,这是我的字符串,我需要正则表达式,它将获取所有id及其值 例如:“id”:“事件”,“id”:“事件”,“id”:“kwd”,“id”:“kwd” 表示每个事件,因此我可以替换或向id添加唯一值 注意:-我不想做数组,不想做循环 寻找用preg_match或任何其他正则表达式方法替换的可能性。我自己得到了答案: preg_match_all(“/”id):“(.*”,/U',$json,$matches,preg_模式顺序) 打印(匹配项);死亡 不要使用正则表达式解析JSON。有。使用json

这是我的字符串,我需要正则表达式,它将获取所有id及其值

例如:“id”:“事件”,“id”:“事件”,“id”:“kwd”,“id”:“kwd”

表示每个事件,因此我可以替换或向id添加唯一值

注意:-我不想做数组,不想做循环


寻找用preg_match或任何其他正则表达式方法替换的可能性。

我自己得到了答案:

preg_match_all(“/”id):“(.*”,/U',$json,$matches,preg_模式顺序)


打印(匹配项);死亡

不要使用正则表达式解析JSON。有。使用
json\u decode()
并将其转换为php数组。执行您想要的任何操作,然后使用
json\u encode()
将其转换回json。顺便说一句,我不是一个不支持的选民,如果我想这样做,我没有问这个问题,为什么这个问题应该得到的答案和你写这个问题时付出的努力一样多,这是零。请花些时间完成并通读,尤其是在这里发布下一个问题之前。你问了一个问题,却不听取别人在评论中的意见?见和。不要为此使用正则表达式。每个人都通过将其转换为数组来完成这件事,我的动机只是在字符串中使用正则表达式。
{
    "status": "success",
    "data": {
        "title": "test2",
        "json_query": {
            "condition": "AND",
            "rules": [{
                "id": "event",
                "field": "event",
                "type": "string",
                "operator": "equal",
                "value": "signup"
            }, {
                "condition": "AND",
                "rules": [{
                    "id": "event",
                    "field": "event",
                    "type": "string",
                    "operator": "equal",
                    "value": "signup"
                }, {
                    "condition": "AND",
                    "rules": [{
                        "id": "kwd",
                        "field": "kwd",
                        "type": "string",
                        "operator": "equal",
                        "value": "epub"
                    }]
                }]
            }, {
                "id": "kwd",
                "field": "kwd",
                "type": "string",
                "operator": "equal",
                "value": "arts"
            }, {
                "condition": "AND",
                "rules": [{
                    "id": "kwd",
                    "field": "kwd",
                    "type": "string",
                    "operator": "equal",
                    "value": "automotive"
                }, {
                    "condition": "AND",
                    "rules": [{
                        "id": "kwd",
                        "field": "kwd",
                        "type": "string",
                        "operator": "equal",
                        "value": "books"
                    }, {
                        "condition": "AND",
                        "rules": [{
                            "id": "kwd",
                            "field": "kwd",
                            "type": "string",
                            "operator": "equal",
                            "value": "business"
                        }, {
                            "condition": "AND",
                            "rules": [{
                                "id": "kwd",
                                "field": "kwd",
                                "type": "string",
                                "operator": "equal",
                                "value": "books"
                            }]
                        }]
                    }]
                }]
            }]
        }
    }
}