簡體   English   中英

正則表達式與PHP中的正則表達式不匹配

[英]Regex not matching regex in PHP

我目前正在一個涉及regex的項目中工作。 我想知道為什么或如何讓此遞歸正則表達式在PHP中工作:

/\(((?:(?:[^?+*{}()[\]\\|]+|\\.|\[(?:\^?\\.|\^[^\\]|[^\\^])(?:[^\]\\]+|\\.)*\]|\((?:\?[:=!]|\?<[=!]|\?>)?(?1)??\)|\(\?(?:R|[+-]?\d+)\))(?:(?:[?+*]|\{\d+(?:,\d*)?\})[?+]?)?|\|)*)\)/

它應與以下文本匹配(例如):

{{"test":"([a-f0-9]{32})"},{"test2":"([a-z]{3})"}}

給定的結果應該是一個包含以下內容的數組:

  • [a-f0-9]{32}
  • [az]{3}

編輯:

$from = '{{"test":"([a-f0-9]{32})"},{"test2":"([a-z]{3})"}}'; 
preg_match_all("/(((?:(?:[^?+*{}()[]\\|]+|\\.|[(?:\^?\\.|\^[^\]|[^\\^])(?:[^]\]+‌​|\\.)*]|((?:\?[:=!]|\?<[=!]|\?>)?(?1)??)|(\?(?:R|[+-]?\d+)))(?:(?:[?+*]|\{\d+‌​(?:,\d*)?\})[?+]?)?|\|)*))/", $from, $output_array, PREG_OFFSET_CAPTURE); 
var_dump($output_array);

為什么這么復雜?

preg_match ('/\:"\((.*)\)"/', $search, $ matches);

看來您只想要:"()"之間的值?

匹配項為$ matches。

參見http://php.net/manual/en/function.preg-match.php

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM