Hello, I really need help with this, thank you in advance
clipboard item is below ;
clip := clipboard
Get an appointment
07-Sep-19, Saturday 02:00pm - 04:00pm
That line changes everytime with different information but still presents 17:00
07-Sep-19, Saturday 03:00pm - 05:00pm
That line changes everytime with different information but still presents 18:00
08-Sep-19, Sunday 08:00am - 10:00am
That line changes everytime with different information but still presents 11:00
08-Sep-19, Sunday 01:00pm - 03:00pm
That line changes everytime with different information but still presents 16:00
08-Sep-19, Sunday 02:00pm - 04:00pm
That line changes everytime with different information but still presents 17:00
I am trying to get time and date separately as a variable for each option.
Date1; 07-Sep-19, Saturday
time1 ; 02:00pm - 04:00pm
Date2: 07-Sep-19
Time2: 03:00pm - 05:00pm
by this way, I will make a script if the dates are the same or different.
RegExMatch(clip, "O)Get an appointment \r\n(?<dat1>.*)\,\n(?<tim1>.*)\r\n(?<dur>.*)\r\n(?<dat2>.*)\,\n(?<tim2>.*)\r\n", apt)
dat11 := % apt["dat1"]
tim11 := % apt["tim1"]
dat22 := % apt["dat2"]
tim22 := % apt["tim2"]
dur := % apt["dur"]
If dat11 = % dat22
Msgbox, " . dat11 . ", between " . tim11 . " or " . tim22 . " ?
If dat11 != % dat22
Msgbox, " . dat11 . ", between " . tim11 . " or " . dat22 . " " . tim22 . " ?
regexmatch from clipboard
Re: regexmatch from clipboard
This captures the dates and times into arrays:
Code: Select all
Clip =
(
Get an appointment
07-Sep-19, Saturday 02:00pm - 04:00pm
That line changes everytime with different information but still presents 17:00
07-Sep-19, Saturday 03:00pm - 05:00pm
That line changes everytime with different information but still presents 18:00
08-Sep-19, Sunday 08:00am - 10:00am
That line changes everytime with different information but still presents 11:00
08-Sep-19, Sunday 01:00pm - 03:00pm
That line changes everytime with different information but still presents 16:00
08-Sep-19, Sunday 02:00pm - 04:00pm
That line changes everytime with different information but still presents 17:00
)
Date := []
Time := []
StartPos := 1
loop
{
FoundPos := RegExMatch(clip, "O)(\d{2}-\w{3}-\d{2}, \w+) (\d{2}:\d{2}\w{2} - \d{2}:\d{2}\w{2})", Match, StartPos)
if !FoundPos
break
Date.Push(Match[1])
Time.Push(Match[2])
StartPos := FoundPos + StrLen(Match[1]) + StrLen(Match[2])
}
; show captured data:
loop, % Date.Count()
TextOut .= Date[A_Index] " >> " Time[A_Index] "`n"
MsgBox, %TextOut%
Re: regexmatch from clipboard
Thank you for the reply, I tried this but it shows empty message box for some reason.
Re: regexmatch from clipboard
What version of AHK are you using? You could run this script to find out:
Code: Select all
MsgBox % A_AhkVersion
Re: regexmatch from clipboard
version;
1.1.23.01
1.1.23.01
Re: regexmatch from clipboard
You can either update to the latest version, or this change should work:
From:
loop, % Date.Count()
To:
loop, % Date.MaxIndex()
From:
loop, % Date.Count()
To:
loop, % Date.MaxIndex()
Re: regexmatch from clipboard
I tried with the new version;
it gives this result;
Date[A_Index] " >> " Time[A_Index] "
it gives this result;
Date[A_Index] " >> " Time[A_Index] "
Re: regexmatch from clipboard
oh okay it worked, thank you so much.
is there any way that I can get each date and time as a separate variable?
I am trying to get the first and second date and time both separately as a variable.
is there any way that I can get each date and time as a separate variable?
I am trying to get the first and second date and time both separately as a variable.
Re: regexmatch from clipboard
They are separate variables. Each date is Date[1], Date[2], etc., and the corresponding times are Time[1], Time[2], etc. They were just shown next to each other in the MsgBox, but they are separate.
Do you mean you're rather have them as Date1, Date2, etc., and Time1, Time2, etc? There's really no advantage to that.
Do you mean you're rather have them as Date1, Date2, etc., and Time1, Time2, etc? There's really no advantage to that.
Re: regexmatch from clipboard
Yes, I will put them on gui interface one by one to the specific buttons with a better clickable copy button.
Oh perfect, yes I can call them as Date [1] ... Date [2] etc..
that is perfect, thank you a lot
Oh perfect, yes I can call them as Date [1] ... Date [2] etc..
that is perfect, thank you a lot
Re: regexmatch from clipboard
Glad to help.
Just note that there is no space in Date[1] (i.e. it's not Date [1] as you typed in your last message). Just trying to save you time hunting down a future problem.
Just note that there is no space in Date[1] (i.e. it's not Date [1] as you typed in your last message). Just trying to save you time hunting down a future problem.
Re: regexmatch from clipboard
Thank you so much Boiler, that was amazing,
I have one more question ;
for below condition now I am editing the regexmatch you provided but I couldn't be successful ;
clipboard is below;
there is tab before date .
between date and comes section there is a space and tab
But that didn't work for this case, possibly I couldn't make that regex correct way. Could you please let me know how it should be for this case?
I have one more question ;
for below condition now I am editing the regexmatch you provided but I couldn't be successful ;
clipboard is below;
there is tab before date .
between date and comes section there is a space and tab
Code: Select all
Thu, Sep 5 comes 11:00AM - 1:00PM
Thu, Sep 5 comes 12:00PM - 2:00PM
Thu, Sep 5 comes 1:00PM - 3:00PM
Thu, Sep 5 comes 2:00PM - 4:00PM
« Previous
;instead of
FoundPos := RegExMatch(clip, "O)(\d{2}-\w{3}-\d{2}, \w+) (\d{2}:\d{2}\w{2} - \d{2}:\d{2}\w{2})", Match, StartPos)
;I tried
FoundPos := RegExMatch(clip, "O)(w{3},\ w{3} \d+) (\d{2}:\d{2}\w{2} - \d{2}:\d{2}\w{2})", Match, StartPos)
Re: regexmatch from clipboard
If I understood how you said it's formatted correctly, try this:
It should match (for example): Thu, Sep 5 for date and 11:00AM - 1:00PM for time.
Code: Select all
FoundPos := RegExMatch(clip, "O)((\w{3}, \w{3} \d+)\s+comes (\d+:\d{2}\w{2} - \d+:\d{2}\w{2})", Match, StartPos)
Re: regexmatch from clipboard
Now I tried yours which looks great and thank you so much again,
and that works like charm
and that works like charm
-
- Posts: 4326
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: regexmatch from clipboard
Just for fun:
Code: Select all
Clip =
(
Thu, Sep 5 comes 11:00AM - 1:00PM
abc
Thu, Sep 5 comes 12:00PM - 2:00PM
def
Thu, Sep 5 comes 1:00PM - 3:00PM
Thu, Sep 5 comes 2:00PM - 4:00PM
mno
Thu, Sep 5 comes 3:00PM - 5:00PM
)
dates := RegExReplace(Clip, "s).*?(\w+,\s\w+\s\d+\scomes\s(\d+:\d+\w+)\s-\s(?-1)(?(?=.*?(?-2))\R))|.*", "$1")
Date := []
Time := []
for k, v in StrSplit(dates, [" comes ", "`n"], "`r")
([Time, Date][mod(k, 2) + 1]).Push(v)
for k in Date
TextOut .= Date[k] " >> " Time[k] "`n"
MsgBox, %TextOut%