tags:

views:

92

answers:

4

Need to an expression that returns only things with an "I" followed by either a "J" or a "V" (No Quotes) and then a minimum of 1 number up to 3 numbers.

I J### I V### I J## I V## I J# I v#

Thank to everyone who has already helped!

+4  A: 

Depends on your flavor

I(J|V)[0-9]{1,3}

Do you also need a space after an "I"?

I (J|V)[0-9]{1,3}
chakrit
+4  A: 

Your description does not match your example, and there are some idiomatic things that you'll need to take care of (case insensitivity, that depends on the regex engine)

I [JV]\d{1,3}

This will match

  • I J1
  • I J12
  • I J123
  • I V1
  • I V12
  • I V123

But WILL NOT MATCH

  • I 1
  • I 12
  • I 123
Vinko Vrsalovic
+1  A: 

Tested with RegExBuddy:

I [JV]\d{1,3}\s

Edited:

Pretty much like Vinko Vrsalovic one, but with his, if you have I J12345678, It will grab "I J123" in your expression. Adding \s demands a special char at the end, like a space, line feed, etc...

vIceBerg
Yes. But that depends on how will it be used. For example it might be better to end it with $ instead of \s, or just leave it without it.
Vinko Vrsalovic
You're right. But according to his example, the data is is one single line. So, using $ will only work if there's one I J123 value in the string...
vIceBerg
A: 

I think the others missed the v# spec.

I[JVv]\d{1,3}

Of course perhaps the lowercase v was a typo.

Axeman