tags:

views:

150

answers:

2

Currently this expression "I ([a-zA-z]\d]{3} " returns when the following pattern is true:

I AAA 
I Z99 

I need to modify this so it will return a range of alphanumerics after the I from 2 to 13 that do not have a space.

Example:

I AAA 
I A321 
I ASHG310310 

Thanks,

Dave

+7  A: 

Without the quotes:

"I ([a-zA-Z\d]{2,13}) "
Tomalak
don't forget the closing paren ")"
Keng
Yeah. I foolishly copied from the question and changed the missing part only because the author stated that this was what he had working. Can't imagine what he has really works.
Tomalak
I recommend http://regexpal.com/ where you can evaluate your regexps and get instant visual feedback. A real time saver.
some
Nice tool. *bookmarked*
Tomalak
+2  A: 

The {} brackets allow two parameters seperated by a comma, which indicates the minimum and maximum number of repetitions. Also, I'm not sure if your original regex gets what you intend - as it's written, it accepts 3 groups of a letter and a number.

You may want to try

I ([a-zA-Z]|\d){2,13}

There's a reference page here: http://www.regular-expressions.info/reference.html

Raymond Martineau
It's much more efficient to put the \d inside the character class, like Tomalak did.
Alan Moore