astralaaron Posted July 15, 2015 Share Posted July 15, 2015 (edited) I have a really hard time understanding how to write regular expressions..even when looking at examples. I am trying to match a (word)(3-4 digit number)(anotherword) for example "firstname4343lastname". I need to make sure it is in that format. I've been trying many different things, but here is the most recent: http://jsfiddle.net/6ajj95af/ Any help is appreciated. Also, I will need to extract the number after confirming the format, any advice as to the best / most efficient way to do that would also be a really big help right now. Thank you everyone EDIT: The JSFiddle is sort of a bad example, just to clarify: The "firstname" and "lastname" are actually meant to be fixed words... it is something like worda2738wordb the number is variable. Edited July 15, 2015 by astralaaron Link to comment Share on other sites More sharing options...
Ingolme Posted July 15, 2015 Share Posted July 15, 2015 This works: var reg = /firstnamed{2,4}lastname/i The main problem is probably that you have to escape the backslash since it's inside a string. If you make a literal regular expression you won't encounter that problem. In simpler terms, if it's between quotation marks, d needs to be d Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now