Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javascript RegEx Question

 
Alex Wong
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to match the following pattern:

7 numeric digits optionally followed by an 'x'. If there is an 'x', then the 'x' needs to be followed by at least one digit.

Here's what I have so far for my regex:
[0-9]{7}x(?=[0-9]+)?

Edit: To clarify, the issue with my current regex is getting it to match the case of just 7 digits without the 'x'.
[ June 09, 2008: Message edited by: Alex Wong ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well [0-9] is \d so you can shorten it up a bit

I think it should be something like this:




Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic