Page 2 of 2

Re: If var is a date, how?

Posted: 30 Jun 2022, 07:20
by Krd
Lol, wow guys :D


Edit:

I like Bingo and Bongo!

Re: If var is a date, how?

Posted: 02 Jul 2022, 19:10
by Emile HasKey
Another way.

Code: Select all

; check date is valid:
date1 := "13.12.2020"
date2 := "33.12.2020"
MsgBox % Is_dd_MM_yyyy(date1) ; True
MsgBox % Is_dd_MM_yyyy(date2) ; False
return

Is_dd_MM_yyyy(date)
{
	local date2
	if !RegExMatch(date, "^\d{2}\.\d{2}\.\d{4}$")
		return False

	date2 := Format("{3:04}{2:02}{1:02}", StrSplit(date, ".")*)
	if date2 is Time
		return True
	return False
}

Re: If var is a date, how?

Posted: 03 Jul 2022, 02:17
by Rohwedder
Emile HasKey's version varied:

Code: Select all

; check date is valid:
date1 := "13.12.2020"
date2 := "33.12.2020"
MsgBox % Is_dd_MM_yyyy(date1) ; True
MsgBox % Is_dd_MM_yyyy(date2) ; False
return

Is_dd_MM_yyyy(date)
{
	; local D ; this does not work!
	if !RegExMatch(date, "^(\d{2})\.(\d{2})\.(\d{4})$", D)
		return False

	D := D3 D2 D1
	if D is Time
		return True
	return False
}

Re: If var is a date, how?

Posted: 03 Jul 2022, 14:13
by Krd
So many good AHK-ers here :)

RegEx is magic. Where to learn all these creepy things that do things I can not understand?

Re: If var is a date, how?

Posted: 04 Jul 2022, 07:19
by boiler
@Krd

https://regexone.com/ is a good place to learn RegEx in a step-by-step tutorial fashion.

https://regex101.com/ is a good place for building and testing your RegEx patterns and is a good reference in general.

Re: If var is a date, how?

Posted: 04 Jul 2022, 12:05
by Krd
I would never be able to find them my self. So RegEx is not AHK-special thing? At least the one used in AHK? I have started with https://www.autohotkey.com/docs/misc/RegEx-QuickRef.htm and I miss some more examples. Coding language is not so easy for a long timer noob :HeHe:

I liked the first link very much. Thank you boiler! :cookie:

Re: If var is a date, how?

Posted: 04 Jul 2022, 14:21
by boiler
Krd wrote: I would never be able to find them my self.
Both of those sites and many others are easily found with a simple google search.

Krd wrote: So RegEx is not AHK-special thing?
No, regular expressions predate AHK by lot.

Krd wrote: At least the one used in AHK?
No, AHK uses Perl Compatible Regular Expression (PCRE), which is a library used by many programming languages.