View previous topic :: View next topic
|
Author |
Message |
jzhardy
Active User
Joined: 31 Oct 2006 Posts: 139 Location: brisbane
|
|
|
|
does anyone know if the result of an ISPF edit search is accessible in an ISPF variable ?
eg, from a REXX macro, i might have something like:
"F r'ab.+z'" which would match, for example, "abcdz"
is the result mapped to any .Z variable ? |
|
Back to top |
|
|
Willy Jensen
Active Member
Joined: 01 Sep 2015 Posts: 734 Location: Denmark
|
|
|
|
The ISPF EDIT macro FIND service will set rc=0 and the special variable .zcsr to the line number if a match is found.
Sample:
"find ' XXMACS ' first nx"
if rc=0 then "change ' ' '*' .zcsr .zcsr first"
See the 'Edit and Edit Macros' manual for details. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2594 Location: Silicon Valley
|
|
|
|
After the FIND is successful, you can use the CURSOR macro statement to get the line number and column value of where the cursor is. Then use the LINE macro statement to get the entire line. Use rexx PARSE statement to break up the line based on the column offset. |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1335 Location: Bamberg, Germany
|
|
|
|
@Pedro: You might not get the RegEx search string in full detail when using parse afterwards. |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1315 Location: Vilnius, Lithuania
|
|
|
|
Use the "macro_msg" edit macro command, and parse the resulting variables, ZEDILMSG, ZEDISMSG, and ZEDMSGNO. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2594 Location: Silicon Valley
|
|
|
|
Quote: |
You might not get the RegEx search string in full detail |
I was guessing it would be a blank delimited string. |
|
Back to top |
|
|
Willy Jensen
Active Member
Joined: 01 Sep 2015 Posts: 734 Location: Denmark
|
|
|
|
Ok, slightly better sample than my first one:
"find 'text' first"
if rc=0 then "(r) = line .zcsr" |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1335 Location: Bamberg, Germany
|
|
|
|
This snippet works for me.
Code: |
"MACRO_MSG = ON"
"F r'ab.+z'"
parse var ZEDISMSG . "'"string"'" .
say string |
|
|
Back to top |
|
|
jzhardy
Active User
Joined: 31 Oct 2006 Posts: 139 Location: brisbane
|
|
|
|
thanks ! works brilliantly
slightly related, is there any way to get capture elements from a matching Regex ?
so, if an input line contained :
xyz : 123
any my match was r'xyz : *([^ ]+) *$'
then it would capture 123 |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1335 Location: Bamberg, Germany
|
|
|
|
Have you tried the code snippet? Guess not.. |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1335 Location: Bamberg, Germany
|
|
|
|
For your RegEx I'd use:
Code: |
^xyz[ ]+:[ ]+([0-9])+.*$ |
|
|
Back to top |
|
|
jzhardy
Active User
Joined: 31 Oct 2006 Posts: 139 Location: brisbane
|
|
|
|
sorry all, some clarification required on my part
my follow up was more about capture elements specifically. A regex expression can have one or more capture elements, identified by bracket pairs.
so, r'x(..)y(..)' would capture :
xyzyab
returning yz into capture element 1 and 'ab' into capture element 2. This is supported by a full implementation of REgex, but suspect it is not possible in ISPF regex. |
|
Back to top |
|
|
jzhardy
Active User
Joined: 31 Oct 2006 Posts: 139 Location: brisbane
|
|
|
|
.. meaning I want to be able to capture an element into a variable ... |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1335 Location: Bamberg, Germany
|
|
|
|
AFAIK it is not (yet) possible with ISPF to have the captured groups as variables. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2594 Location: Silicon Valley
|
|
|
|
Quote: |
it is not (yet) possible with ISPF to have the captured groups as variables. |
You should submit a Request For Enhancment at developerworks. www.ibm.com/developerworks/rfe/ You will need to get an userid |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1335 Location: Bamberg, Germany
|
|
|
|
@Pedro: You only get one or two votes for that and it's being considered niche. Of course ISPF variables ZRE0..9 for up to 10 capture groups are available and it could work like that. The second string in a CHANGE could have r'\0 .. \9' for those variables if the first is also a RegEx but the total unresolved(?) expression length for both must not exceed 256 characters afaik presently. |
|
Back to top |
|
|
|