两个数字使用vbscript的正则表达式:无效:“$123456789012”,有效:“12345678912”

时间:2022-04-02 07:32:28

I wanted to create regular Expression to find the number with 10 or more digits and that number should not have $ symbol in front of it.

我想要创建一个正则表达式来查找10位或10位以上的数字,这个数字前面不应该有$符号。

Eg: not valid:$123456789012 and valid: 12345678912.

无效:$123456789012,有效:12345678912。

Apart from this I have more validations for example finding number pattern: 3digits - 4digits, 3digits - 4digits - 5digits.

除此之外,我还有更多的验证,例如找到数字模式:3位数- 4位数,3位数- 4位数- 5位数。

But for now I am able to create pattern for all those but unable to do for $<number>, could you please help.

但是现在我可以为所有这些创建模式,但是不能为$ 做,请您帮忙。

Sorry for not mentioning in the beginning - this is using vbscript.

很抱歉在开始时没有提到—这是使用vbscript。

Code:

代码:

RegularExpressionObject.IgnoreCase = True 
RegularExpressionObject.Global = True 
RegularExpressionObject.Pattern =
    "(([0-9]{3}-[0-9]{4})|([0-9]{3}-[0-9]{4}-[0-9]{5})|([0-9]{3}-[0-9]{4}-[0-9]{5}-[‌​0-9]{6})|([0-9]{10}))"
    'pattern:CCID or 3(digits)-4(digits), 3(digits)-4(digits)-5(digits), 3(digits)-4(digits)-5(digits)-6(digits), 10digts and above number 
Set Matches = RegularExpressionObject.Execute(Rescomts)
    If (Matches.Count <> 0) Then 

In the above code, regular expression pattern 10 digits are allowed, but I wanted to ignore 10 digits starting from $ symbol

在上面的代码中,允许使用正则表达式模式10位,但是我想要忽略从$符号开始的10位数字。

2 个解决方案

#1


3  

As @Sam said, you would probably use a negative look-behind:

正如@Sam所说,你可能会使用一个消极的视角:

(?<!\$)\b[0-9]{10,}\b

Example: http://regex101.com/r/vR3iF6

例如:http://regex101.com/r/vR3iF6

Depending on the language selected, look-around may not be available. For example, Javascript limits the use of (?<!\$) so you may need to write it as

根据所选语言的不同,查找可能不可用。例如,Javascript限制了(?

[^$]\b[0-9]{10,}\b

Example: http://regex101.com/r/oH5uE4

例如:http://regex101.com/r/oH5uE4

Some languages support \d, which may make your regex look cleaner. Others don't, and you'll need to write [0-9].

有些语言支持\d,这可能会使您的regex看起来更干净。其他人没有,你需要写[0-9]。

EDIT Per @AlanMoore's suggestion, extraneous characters may also interfere. You might be able to get around this by using \b[^$]\b instead of just a single \b:

根据@AlanMoore的建议进行编辑,多余的字符也可能会干扰编辑。你可以绕过这个限制使用b \[^ $]\ b,而不只是一个\ b:

\b[^$]\b[0-9]{10,}\b

Example: http://regex101.com/r/lL2bN9

例如:http://regex101.com/r/lL2bN9

This would get rid of preceding spaces, non-digit characters, etc.

这将去掉前面的空格、非数字字符等。

#2


0  

This regular expression seems to work:

这个正则表达式似乎是有效的:

^[^\$][0-9]{9,}$

#1


3  

As @Sam said, you would probably use a negative look-behind:

正如@Sam所说,你可能会使用一个消极的视角:

(?<!\$)\b[0-9]{10,}\b

Example: http://regex101.com/r/vR3iF6

例如:http://regex101.com/r/vR3iF6

Depending on the language selected, look-around may not be available. For example, Javascript limits the use of (?<!\$) so you may need to write it as

根据所选语言的不同,查找可能不可用。例如,Javascript限制了(?

[^$]\b[0-9]{10,}\b

Example: http://regex101.com/r/oH5uE4

例如:http://regex101.com/r/oH5uE4

Some languages support \d, which may make your regex look cleaner. Others don't, and you'll need to write [0-9].

有些语言支持\d,这可能会使您的regex看起来更干净。其他人没有,你需要写[0-9]。

EDIT Per @AlanMoore's suggestion, extraneous characters may also interfere. You might be able to get around this by using \b[^$]\b instead of just a single \b:

根据@AlanMoore的建议进行编辑,多余的字符也可能会干扰编辑。你可以绕过这个限制使用b \[^ $]\ b,而不只是一个\ b:

\b[^$]\b[0-9]{10,}\b

Example: http://regex101.com/r/lL2bN9

例如:http://regex101.com/r/lL2bN9

This would get rid of preceding spaces, non-digit characters, etc.

这将去掉前面的空格、非数字字符等。

#2


0  

This regular expression seems to work:

这个正则表达式似乎是有效的:

^[^\$][0-9]{9,}$