Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I need this regular expression for this format

(##.####)

I think it should be something like this

/[0-9]*[.][0-9]/
share|improve this question
3  
Have you tried anything so far? – Jerry 8 hours ago
What regular expression did you try and that did not work? – Sarwar Erfan 8 hours ago
I dont have any strong idea. i think i should be like this /[0-9]*[.][0-9]/ – Siraj Hussain 8 hours ago
@fnkr: Note the tag JavaScript... – Elias Van Ootegem 8 hours ago
@fnkr: XRegExp is a lib, not the native JS RegExp constructor. Besides, for something this easy, there really isn't a need to overcomplicate things IMO – Elias Van Ootegem 8 hours ago

closed as too localized by Michael Petrotta, mplungjan, elclanrs, Jerry, Pete 6 hours ago

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

2 Answers

up vote 0 down vote accepted

I'll bite. This should work:

var re = /(^\d{2}\.\d{4}$)/;
(^    - begin
\d{2} - match two digits
\.    - the period between digit sets
\d{4} - match four digits
$)    - end

And if you need the parantheses:

var re = /(^\(\d{2}\.\d{4}\)$)/;

jsFiddle

share|improve this answer
1  
It's working. Thanks – Siraj Hussain 7 hours ago
You're welcome. – ChristopherW 7 hours ago

I assume, that the brackets does not belong to the pattern.

Use the quantifier {x} where x is the number of repetitions you want to find. With \d you can match a digit.

The next important point is, you need to anchor your regex to avoid getting partial matches:

  1. You want to find the word within a longer string

    use the word boundary \b to ensure that there is no other word character before and after your pattern.

    /\b\d{2}\.\d{4}\b/
    
  2. The complete string should fit that pattern

    Use the anchors ^ and $ to match the start and the end of the string.

    /^\d{2}\.\d{4}$/
    
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.