Hello everyone, I'm trying to use regexmatch a variable above instead of below,
clip = (
My ConnectionsAll Connections
0 2 1
nma2
example (not this one)
example (not this one)
others
details
others
details
changing variables
abovedetails
07 Nov. 2019
belowdetails
RegExMatch(clip, "O)07 Nov. 2019 \r\n(?<date>.*)\r\n", Match)
that one gives me below details,
how can I get the above details ?
Thank you everyone for these amazing forum and being helpful...
parsing above with regexmatch instead of below Topic is solved
-
- Posts: 73
- Joined: 27 Sep 2019, 01:44
Re: parsing above with regexmatch instead of below
Code: Select all
myVariable =
(
abc
07 Nov. 2019
def
)
RegExMatch(myVariable, "(.*)(07 Nov. 2019)(.*)", myResult)
MsgBox % ""
. myResult "`n`n"
. myResult1 "`n"
. myResult2 "`n"
. myResult3
Re: parsing above with regexmatch instead of below
that didn't work when the date is a variable,
at a point I need to put the date as a variable
itried as
RegExMatch(myVariable, "(.*)(" myvar ")(.*)", myResult)
MsgBox % myResult1 "`n"
it shows empty
any suggestion?
Thank you
at a point I need to put the date as a variable
itried as
RegExMatch(myVariable, "(.*)(" myvar ")(.*)", myResult)
MsgBox % myResult1 "`n"
it shows empty
any suggestion?
Thank you
-
- Posts: 73
- Joined: 27 Sep 2019, 01:44
Re: parsing above with regexmatch instead of below
yes...
that is impossible
that is impossible
Re: parsing above with regexmatch instead of below
Based on the other thread from https://www.autohotkey.com/boards/viewtopic.php?f=76&t=69631
the following should add the 'details' to the match.. it's trivial to just match the previous line.
the following should add the 'details' to the match.. it's trivial to just match the previous line.
Code: Select all
#NoEnv
SetBatchLines, -1
nma2 := "nma2"
clip := "
(Join`r`n
zzzzzz
xxxxx
nma2
X example (not this one)
Y example (not this one)
yyyyy
nma2
07 Nov. 2019 (I need this detail)
instructions (I need these details)
example | 10:42am (I need this detail as well but only time)
)"
Matches := [], Match := "", p := 1
while p := RegExMatch(clip, "O)(?<details>.+)\R" nma2 "\R(?<date>.*)\R(?<inq>.*)\R", Match, p + StrLen(Match.Value))
Matches.Push({"inq": Match.inq, "date": Match.date, "details": Match.details})
;=======================================================================================================================
MsgBox % Matches[1, "details"] "`n"
. Matches[1, "date"] "`n"
. Matches[1, "inq" ] "`n`n"
. Matches[2, "details"] "`n"
. Matches[2, "date"] "`n"
. Matches[2, "inq" ]
;=======================================================================================================================
for MatchNumber, Match in Matches
MsgBox % "Match number: " MatchNumber "`nDetails: " Match.details "`nDate: " Match.date "`nInq: " Match.inq
;=======================================================================================================================
- flyingDman
- Posts: 883
- Joined: 29 Sep 2013, 19:01
Re: parsing above with regexmatch instead of below
Try this to see if that fit your needs (not regex but...)
Code: Select all
date := "07 Nov. 2019"
clip =
(join`r`n
My ConnectionsAll Connections
0 2 1
nma2
example (not this one)
example (not this one)
changing variables
others
details
others 2
details
abovedetails
date
belowdetails
others 3
)
for x,y in arr := strsplit(clip,"`r","`n")
try
if (%y% = date)
break
catch e
continue
msgbox % arr[x-1]
msgbox % arr[x+1]
Re: parsing above with regexmatch instead of below
Actually none of them worked in that specific script I will share as exactly;
myVariable =
(
needs these details here
example | 07:33pm
def
Start time
07 Nov. 2019 | 07:33pm
)
nma2 = example
RegExMatch(myVariable, "O)Start time \r\n(?<time>.*)\r\n", Catch)
Tma := % Catch["time"]
RegExMatch(tma, "(.*) \| (.*)", x)
nma3 := "" nma2 " | " x2 ""
RegExMatch(myVariable, "(.*)(" nma3 ")(.*)", myResult)
MsgBox % myResult1 "`n"
I was tyring to only get the line above of "" example | 07:33pm ""
which is """ needs these details here """
by the way there are multiple "" example | 07:33pm "" on my variable text string and I need to identify the first one and get the above line of that first exact variable : example | 07:33pm
myVariable =
(
needs these details here
example | 07:33pm
def
Start time
07 Nov. 2019 | 07:33pm
)
nma2 = example
RegExMatch(myVariable, "O)Start time \r\n(?<time>.*)\r\n", Catch)
Tma := % Catch["time"]
RegExMatch(tma, "(.*) \| (.*)", x)
nma3 := "" nma2 " | " x2 ""
RegExMatch(myVariable, "(.*)(" nma3 ")(.*)", myResult)
MsgBox % myResult1 "`n"
I was tyring to only get the line above of "" example | 07:33pm ""
which is """ needs these details here """
by the way there are multiple "" example | 07:33pm "" on my variable text string and I need to identify the first one and get the above line of that first exact variable : example | 07:33pm
- flyingDman
- Posts: 883
- Joined: 29 Sep 2013, 19:01
Re: parsing above with regexmatch instead of below Topic is solved
Ok, I'll have one more try.
This is what I understood: You have a string called MyVariable. One of the lines in MyVariable consists of the words "Start time". The line just below that consist of a date and a time separated by " | ". We then need that time to find a line that consists of (a) the string contained in the variable "nma2" (in this case it is the word "example") and b) the time we previously found separated by " | ". Once we have found that line, we need the script to return the line just above that.
If that is correct, the following should work:
This is what I understood: You have a string called MyVariable. One of the lines in MyVariable consists of the words "Start time". The line just below that consist of a date and a time separated by " | ". We then need that time to find a line that consists of (a) the string contained in the variable "nma2" (in this case it is the word "example") and b) the time we previously found separated by " | ". Once we have found that line, we need the script to return the line just above that.
If that is correct, the following should work:
Code: Select all
myVariable =
(join`r`n
test
needs these details here
example | 07:33pm
def
do not need these details here
example | 07:33pm
Start time
07 Nov. 2019 | 07:33pm
)
nma2 := "example"
RegExMatch(myVariable, "Start time\v+.* \| (.*)\v+", x)
RegExMatch(myVariable, "(.*)\v+" nma2 " \|" x1, y)
msgbox % y1
-
- Posts: 73
- Joined: 27 Sep 2019, 01:44
Re: parsing above with regexmatch instead of below
You just do not understand RegExp well. Period.
Re: parsing above with regexmatch instead of below
Yes, that's why I'm here... To learn ... Thank you so much.
Re: parsing above with regexmatch instead of below
flyingDman wrote: ↑08 Nov 2019, 15:00Ok, I'll have one more try.
This is what I understood: You have a string called MyVariable. One of the lines in MyVariable consists of the words "Start time". The line just below that consist of a date and a time separated by " | ". We then need that time to find a line that consists of (a) the string contained in the variable "nma2" (in this case it is the word "example") and b) the time we previously found separated by " | ". Once we have found that line, we need the script to return the line just above that.
If that is correct, the following should work:Code: Select all
myVariable = (join`r`n test needs these details here example | 07:33pm def do not need these details here example | 07:33pm Start time 07 Nov. 2019 | 07:33pm ) nma2 := "example" RegExMatch(myVariable, "Start time\v+.* \| (.*)\v+", x) RegExMatch(myVariable, "(.*)\v+" nma2 " \|" x1, y) msgbox % y1
Thank you so much for your effort and help, really appreciated.
Thanks to this forum and collaboration I'm able to learn more and more every day. Thanks for being understanding and never giving up helping
