简体   繁体   English

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

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

I want a pattern that contains all characters except English and Persian numbers. 我想要一个包含除英语和波斯数字以外的所有字符的模式。 I found this pattern but my problem is how can I do against this pattern. 我找到了这种模式,但是我的问题是如何对付这种模式。

For example contains * and / and ... but not contains 1 2 3 ۱ ۲ ۳. 例如包含*和/和...,但不包含1 2 3 ۱ ۲。

This pattern gets all numbers: 此模式获取所有数字:

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

We might be able to solve this problem by adding our undesired unicodes in a char list, then swiping everything else, which I'm unsure if space would be undesired or not. 我们可以通过在char列表中添加不需要的unicode,然后轻扫其他所有内容来解决此问题,我不确定是否需要使用空格

Maybe, something like this with modification would work: 也许,像这样的修改会起作用:

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

Demo 演示版

We would just replace x with u for JavaScript: 对于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); 

在此处输入图片说明

RegEx 正则表达式

If this wasn't your desired expression, you can modify/change your expressions in regex101.com . 如果这不是您想要的表达式,则可以在regex101.com中修改/更改表达式。

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

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

This should works 这应该工作

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

Demo 演示版

Note: If I forget some Persian digits just add it before ] 注意:如果我忘记了一些波斯数字,请在[ ]之前添加它

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

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