开发者

regExp problem - string is matched but it should not match

iam trying to check if an user has permission to manage an group:

Expression (ou=|||) i开发者_JAVA技巧s the string I'm looking for

/^OU=|||$|,OU=|||$/i

On a string like "ou=whatever", it returns true (-:

I am sure it's a problem with the pipes, but I have no idea how to solve this.

I am using PHP 5.x with preg_match.


Pipes are metacharacters in a regular expression (meaning "or"). You need to escape them:

/^OU=\|{3}$|,OU=\|{3}$/i

Are you sure that you're using the start- and end-of-string anchors correctly? Right now, this regex will only match the strings

OU=|||

and

<any number of characters>,OU=|||


You need to escape the pipes and include some parenthesis for better readability:

/(^OU=\|\|\|$)|(,OU=\|\|\|$)/i


$has_permission = in_array('OU=|||', explode(',', $permission_string));
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜