繁体   English   中英

RegEx用于传递除字符列表以外的所有字符

[英]RegEx for passing all chars except a list of chars

我想要一个包含除英语和波斯数字以外的所有字符的模式。 我找到了这种模式,但是我的问题是如何对付这种模式。

例如包含*和/和...,但不包含1 2 3 ۱ ۲。

此模式获取所有数字:

^[\u0600-\u06FF\s0-9]+$

我们可以通过在char列表中添加不需要的unicode,然后轻扫其他所有内容来解决此问题,我不确定是否需要使用空格

也许,像这样的修改会起作用:

([\s\S].*?)([\x{0600}-\x{06FF}0-9]+)?

演示版

对于JavaScript,我们将用u替换x:

 const regex = /([\\s\\S].*?)([\\u{0600}-\\u{06FF}0-9]+)?/gmu; const str = `everthing we wish to have before 1 2 3 ۱ ۲ ۳ and everything else we wish to have`; const subst = `$1`; // The substituted value will be contained in the result variable const result = str.replace(regex, subst); console.log('Substitution result: ', result); 

在此处输入图片说明

正则表达式

如果这不是您想要的表达式,则可以在regex101.com中修改/更改表达式。

这不是ASCII,也不是波斯数字

[^0-9\۰-\۹]+

这应该工作

/[^\d۱۲۳۴۵۶۷۸۹]/g

演示版

注意:如果我忘记了一些波斯数字,请在[ ]之前添加它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM