By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,964 Members | 1,810 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,964 IT Pros & Developers. It's quick & easy.

What does this do

P: n/a
Im implementing a calendar and cant figure out what this method does
or how it works

// datetime parsing and formatting routimes. modify them if you wish
other datetime format
function str2dt (str_datetime) {
var re_date = /^(\d+)\-(\d+)\-(\d+)\s+(\d+)\:(\d+)\:(\d+)$/;
if (!re_date.exec(str_datetime))
return alert("Invalid Datetime format: "+ str_datetime);
return (new Date (RegExp.$3, RegExp.$2-1, RegExp.$1, RegExp.$4,
RegExp.$5, RegExp.$6));
}

Mostly because of this expression RegEx.$ , which ive never seen
before. What does it do
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ti**********@hotmail.com writes:
Mostly because of this expression RegEx.$ , which ive never seen
before. What does it do


RegExp.$<n> gives you the n'th partial match of the last regualar
expression match.
So, if you match
/a(.*)a(.*)a/.exec("axxxayyyya")
then RegExp.$1 == "xxx" and RegExp.$2 == "yyyy".

I would prefer to use the return value of exec instead:
if ((match = re.exec(string)) {
...match[1]... match[2]...
}

Here match[1] refers to the same as RegExp.$1, but it is not destroyed
by a later regular expression match.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
JRS: In article <5b**************************@posting.google.com >, seen
in news:comp.lang.javascript, ti**********@hotmail.com posted at Thu, 18
Sep 2003 01:30:48 :-
Im implementing a calendar and cant figure out what this method does
or how it works

// datetime parsing and formatting routimes. modify them if you wish
other datetime format
function str2dt (str_datetime) {
var re_date = /^(\d+)\-(\d+)\-(\d+)\s+(\d+)\:(\d+)\:(\d+)$/;
if (!re_date.exec(str_datetime))
return alert("Invalid Datetime format: "+ str_datetime);
return (new Date (RegExp.$3, RegExp.$2-1, RegExp.$1, RegExp.$4,
RegExp.$5, RegExp.$6));


In addition to what Lasse wrote : the function returns a Date Object set
to the browser's-locality date/time in the string, assuming that to be
of the form "D-M-Y h:m:s" where DMYhms are any number >0 of digits and
the date and time are separated by any amount of whitespace. If the
given year is in 00..99, 1900 will be added.

With whatever error there may be in the OS setting of Time Zone and
Summer Time rules; depending on the application, consequences may be
non-obvious or intermittent.

Twice, \ before - is not needed in the RegExp.

Any number can over/under-flow its field, so 31-9-2003 => 1-10-2003 and
25-0-2004 is this Christmas; in other words, there is no value
validation, only a pattern test. See via below.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.