Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #19468
| From | "Tony" <tony.johansson@inport.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Regular expression |
| Date | 2013-04-25 18:04 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <klbk00$8ks$1@dont-email.me> (permalink) |
myDate has the following format ex. 2013/04/22 03:34
I want to use this pattern
var m = myDate.match(/^\d{4}-\d\d-\d\d (\d\d):(\d\d)$/),
hour = +m[1],
min = +m[2];
But before I can use this pattern
I need to change the - to / because the pattern works for format like
format ex. 2013-04-22 03:34
My first attempt is to replace the - with / but when I do so
I get green underline and invalid character
var m = myDate.match(/^\d{4}/\d\d/\d\d (\d\d):(\d\d)$/),
hour = +m[1],
min = +m[2];
My second attempt is to use escape character.
So I add the escape character \ immediately before character / but when I do
so
I get runtime error
var m = myDate.match(/^\d{4}\/\d\d\/\d\d (\d\d):(\d\d)$/),
hour = +m[1],
min = +m[2];
So how should I write to replace - with / in the pattern
//Tony
Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread
Regular expression "Tony" <tony.johansson@inport.com> - 2013-04-25 18:04 +0200
Re: Regular expression Scott Sauyet <scott.sauyet@gmail.com> - 2013-04-25 10:07 -0700
Re: Regular expression "Tony" <tony.johansson@inport.com> - 2013-04-26 11:27 +0200
Re: Regular expression Denis McMahon <denismfmcmahon@gmail.com> - 2013-04-25 18:05 +0000
Re: Regular expression Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-25 21:02 +0200
Re: Regular expression Scott Sauyet <scott.sauyet@gmail.com> - 2013-04-26 11:15 -0700
Re: Regular expression Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-26 21:17 +0200
csiph-web