Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

Need a pretty version of this RegEx

^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*

The following does not work:
^[0-9]\d{7}*

it's a dangling meta character. But it not for the first one.

Any idea how to make a short one that works?

Thanks.
0
newbieweb
Asked:
newbieweb
4 Solutions
 
hieloCommented:
[0-9] is equivalent to \d

So this:
^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*

is equivalent to:
^\d\d\d\d\d\d\d\d*

Of those, only the last \d is optional (due to the * character). That meas it must have at least 7 digits. So what you are after is:
^\d{7,}

By putting the comma after the seven you are saying "or more" - making the whole thing read as:
"it must begin with 7 or more digits."
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
no points, but I would put this:
^\d{7,}$

to make sure you have only digits in the expression (aka your other question)
0
 
newbiewebSr. Software EngineerAuthor Commented:
Both fail. I forgot to say this is C#.NET. Maybe that uses a diffferent flavor or RegEx?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
hieloCommented:
If you have in double quotes try escaping the slash:
"^\\d{7,}"
0
 
ZvonkoSystems architectCommented:
Or escape the String:
@"^\d{8,}"

Open in new window

0
 
newbiewebSr. Software EngineerAuthor Commented:
Thanks!
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now