2015-06-22 384 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是相当不错的。