![](/img/trans.png)
[英]Regex acepting all chars(spaces, accentuated) except numbers and special characters
[英]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\۰-\۹]+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.