Hi all,
Can you people plz tell me whether RegEx can catch strings using "( )" or not?
code:
Let>exeStep=IGNORE "Error !*Child" PRESS WITHIN 2
RegEx>^\s*IGNORE\s+"([^"]*)"((\s+PRESS\s+\S+)|(\s+ENTER\s+\S+)|(\s+TYPE\s+\S+))\s+WITHIN\s+(\d+)\s*$,%exeStep%,0,MatchMe,cnt,0
Can I get MatchMe_1, MatchMe_2 etc.. for $1, $2 etc.. As in PERL?
Capture group in RegEx?!
Moderators: Dorian (MJT support), JRL
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
Yes, the RegEx command in Macro Scheduler uses (....) to capture groups that can be used in replacement strings as $1,$2,...
But there needs to be a match first.
Make sure that you actually do have a match. Make sure that if you have a comma in your matching pattern that you make that pattern into a variable first, or else Macro Scheduler will see the comma as a delimiter in the RegEx command. (This also applies to the data source that is being searched. I usually make both of them variables like vNeedle and vHaystack.
Using your example (even though there are no commas):
It looks like you are searching for strings that start with IGNORE, end with WITHIN and may have PRESS|ENTER|TYPE in the middle with changing parameters for those commands.
I don't have tme to parse your needle right now, but think you could make it easier by eliminating the \s and \d and just using "." instead. Something like this untested example:
Let>vNeedle=^.*IGNORE.*(PRESS|ENTER|TYPE).*WITHIN.*$
But there needs to be a match first.
Make sure that you actually do have a match. Make sure that if you have a comma in your matching pattern that you make that pattern into a variable first, or else Macro Scheduler will see the comma as a delimiter in the RegEx command. (This also applies to the data source that is being searched. I usually make both of them variables like vNeedle and vHaystack.
Using your example (even though there are no commas):
Code: Select all
Let>vNeedle=^\s*IGNORE\s+"([^"]*)"((\s+PRESS\s+\S+)|(\s+ENTER\s+\S+)|(\s+TYPE\s+\S+))\s+WITHIN\s+(\d+)\s*$
Let>vHaystack=%exeStep%
RegEx>%vNeedle%,%vHaystack%,0,MatchMe,cnt,0
It looks like you are searching for strings that start with IGNORE, end with WITHIN and may have PRESS|ENTER|TYPE in the middle with changing parameters for those commands.
I don't have tme to parse your needle right now, but think you could make it easier by eliminating the \s and \d and just using "." instead. Something like this untested example:
Let>vNeedle=^.*IGNORE.*(PRESS|ENTER|TYPE).*WITHIN.*$
Last edited by Bob Hansen on Sun Dec 20, 2009 2:54 am, edited 1 time in total.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
OK, got back to a system with Macro Scheduler.
Using your code sample and my syntax, thie is an example showing you the results of your RegEx using $1..$4 on different lines:
In this example, the third group value $3, can be ignored. It was needed for the OR option to capture the words. I think you only wanted $1, $2, $4.
Using your code sample and my syntax, thie is an example showing you the results of your RegEx using $1..$4 on different lines:
Code: Select all
Let>vNeedle=^.*IGNORE.*"([^"]*)".*(\b(PRESS|ENTER|TYPE)\b.*)WITHIN(.*)$
Let>vHaystack=IGNORE "Error !*Child" TYPE <F1> WITHIN 2
Let>vReplacement=Four Values are:%CRLF%1: $1%CRLF%2: $2%CRLF%3: $3%CRLF%4: $4
RegEx>%vNeedle%,%vHaystack%,0,MatchMe,cnt,1,%vReplacement%,vResult
MessageModal>%vResult%
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
-
- Pro Scripter
- Posts: 63
- Joined: Thu Dec 10, 2009 8:13 am
Thanks Bob for your valuable information.
I used \s,\d etc because I needed it like that..
e.g. I want IGNORE "abcd" not IGNORE123"abcd" ...
Yes I wanted $1, $2 and $4 only. Actually I wanted to catch them outside the RegEx command; but MatchMe_1 or $1 was not working...
Ok I will use replacing method itself..and can later use it.
Thanks..
I used \s,\d etc because I needed it like that..
e.g. I want IGNORE "abcd" not IGNORE123"abcd" ...
Yes I wanted $1, $2 and $4 only. Actually I wanted to catch them outside the RegEx command; but MatchMe_1 or $1 was not working...
Ok I will use replacing method itself..and can later use it.
Thanks..