File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Head First Android this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Javascript RegEx Question" Watch "Javascript RegEx Question" New topic

Javascript RegEx Question

Alex Wong

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:

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

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

I think it should be something like this:

I agree. Here's the link:
subject: Javascript RegEx Question
It's not a secret anymore!