简体   繁体   English

简单的数字正则表达式匹配

[英]Simple Numeric Regex Match

Hi I'm having an issue doing a simple numeric match, what am I doing wrong: 嗨,我在执行简单的数字匹配时遇到问题,我在做什么错:

Criteria: 标准:

1) Always anchor to start
2) Always Numeric 6-7 digits
3) Always Followed by _ (underscore)

Sample: (want to match everything before LoremIpsum) 样本:(想匹配LoremIpsum之前的所有内容)

1212384_LoremIpsum...
1266625_LoremIpsum...
234233_LoremIpsum...
2348199_LoremIpsum...

I have tried a couple of things: (Does not Match) 我尝试了几件事:(不匹配)

^[\d]{6-7}_
^[0-9]{6-7}_

If I do: 如果我做:

^[\d]{6}_
^[0-9]{7}_

I get matches, why can't I do variable length in this expression ? 我得到匹配项,为什么不能在此表达式中执行可变长度? What am I missing here ? 我在这里想念什么?

Thanks ! 谢谢 !

The correct syntax is with a comma: 正确的语法是逗号:

{6,7}

Not: 不:

{6-7}

Also, you don't have to put the \\d in brackets: 另外,您不必将\\d放在方括号中:

^\d{6,7}_

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

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