Regex for fixed length string, starting with multiple words -


i'm trying make regex (js flavor) matches string 17 alphanumeric characters in length , must start either "ab, "de" or "gh". after these 3 possibilities, alphanumeric character accepted.

match:

ab163829f13246915 det639601ba167860 ghf1973771a002957 

don't match

xyz63829f13246915 aaa639601ba167860 bbc1973771a002957 

so far have regex i'm testing on http://regexpal.com/

^(ab|)[a-za-z0-9]{17}$ 

not sure why pipe character required match first example, or why fails when add "de" after pipe.

anyone?

use this:

^(ab|de|gh)[a-za-z0-9]{15}$ 

the first 2 characters take two, need 15 more alphanumeric characters after that.

http://rubular.com/r/rawmiy4xeh


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -