开发者

what's wrong with this regex /^[\p{L}\p{N}. -/\\]+$/u

When using thi开发者_如何学Cs regex /^[\p{L}\p{N}. -/\\]+$/u in php I get an 'internal error while using the pattern' error. It want the matched string to be able to contain backslashes.


You have to escape the / char in the class character or use another delimiter than /.

Also escape the - or put it at the begining or at the end of the char class.

/^[\p{L}\p{N}. \-\/\\]+$/u

#^[\p{L}\p{N}. /\\-]+$#u


$str = '\\';    // = \
$str = '\\\\';  // = \\ (this is what you need for your regex)

So, knowing that, your current regex compiles to:

/^[\p{L}\p{N}. -/\]+$/u

which escapes the "]" character and breaks the regex.

Also your delimiter character "/" and "-" should be escaped inside the regex.

Corrected version:

$regex = '/^[\p{L}\p{N}. \\-\\/\\\\]+$/u';


I suppose your pattern should look like this:

/^[\p{L}\p{N}. -\/\\\]+$/u

You forgot to escape / and \ characters in regex pattern, using .


Curly braces ({}) are used to set occurences of the pattern. Inside braces should be integers. Also, \p is not valid pattern and you have to escape \ and / with \ in regex.

So, if you intend to match \ followed by p, it should be \\p.

And, it completely confuses me, why do you have [] around regex? Is it intended to be a character group? If so, why do you have two {} inside it?

So, what's the string you want to match with this pattern?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜