我有一點幫助的請求,沒有那麼複雜,我想,但我無法弄清楚:PHP正則表達式的幫助需要
這是我的正則表達式:
/:\s*'([^:]*)'/g
(我使用它沒有通過preg_match_all標誌克())
這是要搜索的字符串(通常從jqValidate):
{ messages : { required : 'This 'asdf' "asdf" field is required!', dateISO : 'This is a test...' } , rules : { dateISO : true , required : true } }
這是我所得到的,並希望得到:
array(
0 => array(
0 => : 'This 'asdf' "asdf" field is required!'
1 => : 'This is a test...'
)
1 => array(
0 => This 'asdf' "asdf" field is required!
1 => This is a test...
)
)
這就是問題所在:
這種模式 - 我花了幾個小時,以找出爲是(我可不是好練) - 的作品不錯,但只要我不需要:(冒號)。 如果我在單引號之間的消息文本中使用冒號,則該消息不再匹配。
大多數情況下,我試圖玩弄冒號的否定,但我不知道如何否定一個組,比如「匹配所有發生但冒號」,只有當它們不是由至少一個單引號和任何內容引導時在單引號和冒號之間「。
爲了更清楚一點就是我上面的意思是:
Example: This is a plausible use of a colon in a jqValidate message.
'Example': We probably do not use a colon together with single quotes like this.
Any 'text' here: This is a very unusual 'portion of text'!
我希望你看,什麼是我的問題。任何有用的幫助將非常感激。
Thanx提前,
問候英格瑪
你應該告訴誰在生成這個文本來弄清楚如何發出正確的JSON文本,而不是試圖自己編寫它。 – miken32
@ chris85它看起來像一些混蛋自制的JSON。對於初學者來說,標識符沒有被引用,這使得它不是JSON。也打破引用。 – miken32
直到你定義一些結構之前,真的沒有解決方案。最大的問題是在字符串內部沒有分隔符引用。例如,這可能很容易有效'This'asdf''「asdf」field is required!',dateISO:'這是一個測試...'' – sln