954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Regex ~ refine?

Working with javascript / jquery - Need to have a more precise regex for the following pattern:

Should I have the ignore case included? If so where?

X25b777s44K

The regex I have:

^([A-Z]?)(\d{2})([a-z]?)(\d{3})([a-z]?)(\d{2})([A-Z]?)$

Thank you for your help.

scarlettmoon
Light Poster
28 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

Are the letters optional? Do you want to match all the parts of this? If both not, and if you want case-insensitivity, use something like:

/^[a-z]\d{2}[a-z]\d{3}[a-z]\d{2}[a-z]$/i
twiss
Veteran Poster
1,005 posts since Apr 2010
Reputation Points: 177
Solved Threads: 101
 

Hi ~ Thanks for your reply. Actually the letters are NOT optional, have to be caps and yes need to match all parts of the sequence.

With this scenario, would your solution work?

Thank you.

scarlettmoon
Light Poster
28 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

All of the letters need to be caps?

/^([A-Z])(\d{2})([A-Z])(\d{3})([A-Z])(\d{2})([A-Z])$/

But this will NOT match X25b777s44K.

twiss
Veteran Poster
1,005 posts since Apr 2010
Reputation Points: 177
Solved Threads: 101
 

Not all caps but thank you. What I have is working great. Thanks again for your help!

scarlettmoon
Light Poster
28 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: