只需删除正则表达式中的a-zA-z部分即可

时间:2022-01-16 16:51:40

This is my regex string:

这是我的正则表达式字符串:

'(?!('.$exceptions.')((\W+)|$))[a-zA-Z\-_]+/?$'

$exceptions is a variable contains a string like this :

$ exceptions是一个包含如下字符串的变量:

word1|word2|word3|word4|wordN

I just want to remove the section a-zA-Z which means I want to just delete the rule which checking english chars, because of unicode.

我只是想删除a-zA-Z部分,这意味着我只想删除检查英文字符的规则,因为unicode。

A sample :

一个样品 :

$exception ='word1|word3|word3|word4' ;
$myword = 'a-unicode-statement-like-سلام' ;

If $myword compared with the regex rules string it will not match that because of سلام it is not in a-zA-z range i just want remove this limitation (a-zA-Z)

如果$ myword与正则表达式规则字符串进行比较,那么它将不匹配因为سلام它不在a-zA-z范围内我只想删除此限制(a-zA-Z)

2 个解决方案

#1


1  

Try adding something to match everything else, instead of your a-zA-Z rule.

尝试添加一些内容以匹配其他所有内容,而不是您的a-zA-Z规则。

'(?!('.$exceptions.')(.*))'

EDIT:

After reading your comment below. Maybe a better solution is to use the one proposed for this question: wordpress: how to check if the slug contains a specific word?

阅读下面的评论后。也许更好的解决方案是使用针对此问题提出的解决方案:wordpress:如何检查slug是否包含特定单词?

You can then check using something like this:

然后,您可以使用以下内容进行检查:

$url = $_SERVER["REQUEST_URI"];

$isException = strpos($url, 'word1');

if ($isException !== false)
{
    //url contains word in exceptions!
}

#2


0  

From what I understand, I think you're looking for this:

根据我的理解,我认为你正在寻找这个:

$exceptions = ["word1","word2","word3"];
       // or $exceptions = explode("|",$exceptions) to work with what you have already
if( in_array($string,$exceptions)) {
   // word is in exceptions
}

#1


1  

Try adding something to match everything else, instead of your a-zA-Z rule.

尝试添加一些内容以匹配其他所有内容,而不是您的a-zA-Z规则。

'(?!('.$exceptions.')(.*))'

EDIT:

After reading your comment below. Maybe a better solution is to use the one proposed for this question: wordpress: how to check if the slug contains a specific word?

阅读下面的评论后。也许更好的解决方案是使用针对此问题提出的解决方案:wordpress:如何检查slug是否包含特定单词?

You can then check using something like this:

然后,您可以使用以下内容进行检查:

$url = $_SERVER["REQUEST_URI"];

$isException = strpos($url, 'word1');

if ($isException !== false)
{
    //url contains word in exceptions!
}

#2


0  

From what I understand, I think you're looking for this:

根据我的理解,我认为你正在寻找这个:

$exceptions = ["word1","word2","word3"];
       // or $exceptions = explode("|",$exceptions) to work with what you have already
if( in_array($string,$exceptions)) {
   // word is in exceptions
}