2015-06-22 268 views
0

有人可以幫我嗎? 模式是preg_replace():編譯失敗

/\[url=?\]([a-z0-9:\.\\\/-\s]*?)\[\/url\]/isS 

錯誤:

preg_replace(): Compilation failed: invalid range in character class at offset 26

+0

哪個是人物26? – rghome

回答

1

逃生減號( - )

/\[url=?\]([a-z0-9:\.\\\/\-\s]*?)\[\/url\]/is 

Demo

+0

Thx。現在在偏移23處獲得相同的警告並且改變了模式。 新模式現在是:/\[url=([a-z0-9:\.\\\/-\s]+?)\](.*?)\[\/url\]/isS那就是它是什麼使你的。 – Falk

+0

看我的答案演示 – splash58

1

這應該在PHP中工作(PCRE):

/\[url=?\]([a-z0-9:\.\\\/\-\s]*?)\[\/url\]/is 

首先在你的角色類聲明中跳過-[]否則你會得到一個錯誤的範圍錯誤。

第二個/S修飾符可能不是您的模式的好主意。閱讀:

When a pattern is going to be used several times, it is worth spending more time analyzing it in order to speed up the time taken for matching. If this modifier is set, then this extra analysis is performed. At present, studying a pattern is useful only for non-anchored patterns that do not have a single fixed starting character.

Source

要測試你的正則表達式regex101.com是相當不錯的。