Jump to content
Sign in to follow this  
astralaaron

regular expression trouble

Recommended Posts

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 by astralaaron

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...