tags:

views:

72

answers:

4

I want a regular expression to match input like:

3213.32.2311

Format required is:

  • Four numeric characters
  • a .
  • 2 numeric characters
  • a .
  • 4 numeric characters.
+2  A: 
^\d{4}\.\d{2}\.\d{4}$
Dominic Rodger
(These) (are) (pointless)
Peter Boughton
@Peter - sorry, force of habit. I virtually never write a regex where I don't care about what the different parts are.
Dominic Rodger
Perhaps you should use regex more then. ;) I frequently have quick jobs that don't need captures. But no problem, it's just a little thing that bugs me (though not quite as much as `^(this)$` when `$0` or `\0` is already available). Could be useful to mention both ways in your answer, in case it helps with what the OP is doing. :)
Peter Boughton
+1  A: 

\d{4}\.\d{2}\.\d{4}

kuroutadori
Need to escape the dot.
slebetman
Annoyingly enough I did, but StackOverflow editing escaped it. Had to do \\.
kuroutadori
+1  A: 

Try: \d{4}\.\d{2}\.\d{4}

slebetman
+4  A: 

Get yourself a regex cheatsheet such as http://www.regular-expressions.info/reference.html

fredley
Though they look daunting, they're really not that bad. I can never remember the syntax - so a good cheat sheet is a must.
fredley
Also, reading a guide/cheatsheet and writing the expression yourself will help you learn the syntax much quicker than a copy-paste answer.
Peter Boughton