permaculture playing cards*
The moose likes HTML, CSS and JavaScript and the fly likes Javascript RegEx Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Javascript RegEx Question" Watch "Javascript RegEx Question" New topic
Author

Javascript RegEx Question

Alex Wong
Greenhorn

Joined: Jul 27, 2007
Posts: 4
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
well [0-9] is \d so you can shorten it up a bit

I think it should be something like this:




Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javascript RegEx Question