Alex Rivera | Logout

How to represent a fix number of repeats in regular expression?

Asked 2010-07-16T02:44:50.573
79

Is there a better way to represent a fix amount of repeats in a regular expression?

For example, if I just want to match exactly 14 letters/digits, I am using ^\w\w\w\w\w\w\w\w\w\w\w\w\w\w$ which will match a word like UNL075BE499135 and not match UNL075BE499135AAA is there a handy way to do it? I am currently doing it in Java, but I guess this may apply to other language as well.

Edit
Report

1 Answer

21

^\w{14}$ in Perl and any Perl-style regex.

If you want to learn more about regular expressions - or just need a handy reference - the Wikipedia Entry on Regular Expressions is actually pretty good.

answered 2010-07-16T02:46:54.863

Your Answer