开发者

How to specify the amount of characters to be matched?

开发者 https://www.devze.com 2023-01-18 10:42 出处:网络
I have these asset ID\'s in a CMS and I need to update them all with regular expresssions开发者_如何转开发.

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


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.


Nevermind! That was super easy...

The answer is:

/[0-9]{9}/

0

精彩评论

暂无评论...
验证码 换一张
取 消