On Mon, 6 Feb 2012 15:02:42 +0000, Martin Packer wrote:

>Looks to me like it's being greedy. Look up the term "greedy" in relation
>to Regexps and you'll see the match is much wider than you anticipated -
>matching many more characters. Not sure if awk can do non-greedy matching.
>But there are usually workarounds if not.
> 
Mostly, it can't.


>From: Ken MacKenzie 
>To: [email protected],
>Date: 06/02/2012 14:53
>
>I'm not sure if this is the appropriate forum, please point me to the
>correct one if it's not.
>
There's also MVS-OE.
>I'm playing around with regular expressions and I want to achieve the
>following.  I spoke to a Unix geek but he didn't really understand what I
>was asking.
>
>Given the following sample data, I want discover only the first occurrence
>of any string which matches my regexp.
>QQQQABCDEFGNOPQRXXXPPPPABCDEFGNOPQRYYYOOOOABCDEFGNOPQRZZZ
>
>I tried: awk 'sub(/CD.*QR/,"junkt")' fxdata in an attempt to change
>QQQQABCDEFGNOPQRXXX to QQQQABjunktXXX but instead, it takes the final
>occurrence of QR, and returns QQQQABjunktZZZ. Notice the ZZZ on the end
>instead of XXX.
> 
You might try:

    sub(/CD[^Q]*QR/,"junkt")  # Wildcard matches no string containing "Q".

>This is being driven from a REXX exec in ISPF, if any of the above is not
>clear, I will try to explain further.
> 
Eek!  Are you using SYSCALL spawn in an EDIT macro for that?  I thought
only John M., Kirk, and I did that sort of thing.

--gil

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to