tags:

views:

22

answers:

2

Hello,

I have these asset ID's in a CMS and I need to update them all with regular expresssions.

They are 8 or 9 characters in length and made of all numeric characters (0-9). Is there a way to match only 8 or 9 numbers? I'm afraid I may not be using the right keywords in my google search to figure this out and I haven't found anything in my cheat sheets or books yet so I'm hoping someone here might be able to point me in the right direction.

seth

+2  A: 

Most regex flavors allow you to specify the number of characters to match as such (I use a PCRE example):

/^[0-9]{8,9}$/

The {8,9} indicates a minimum of 8 digits to match and a maximum of 9 digits to match. The ^ and $ ensure only entire strings of 8 or 9 digits are matched, and not just substrings.

BoltClock
This one works better :)
Depending on the regex implementation and whether it has a `find` or `match` method, you may or may not need the `^` and `$`.
Kaleb Pederson
A: 

Nevermind! That was super easy...

The answer is:

/[0-9]{9}/

That won't match strings of exactly 8 digits in length.
BoltClock