Do you need to escape the '?' -----Original Message----- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@bama.ua.edu] On Behalf Of Ken MacKenzie Sent: Monday, February 06, 2012 10:44 AM To: IBM-MAIN@bama.ua.edu Subject: Re: Regular Expressions (OMVS)
Yes, I pretty much understand the concept of GREEDY. AFAICS I'm supposed to be able to use a ? To stop on first occurrence (eg awk 'gsub(/CD.*?QR/,"junkt")' fxdata ) but when I do that I get: awk: /CD.*?QR/: FSUMB031 ?, *, + or - - not preceded by valid regular expression Context is: >>> gsub(/CD.*?QR/ <<< From: Martin Packer <martin_pac...@uk.ibm.com> To: IBM-MAIN@bama.ua.edu Date: 06/02/2012 15:04 Subject: Re: Regular Expressions (OMVS) Sent by: IBM Mainframe Discussion List <IBM-MAIN@bama.ua.edu> 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. (And this just about exhausts my knowledge on the greedy vs non-greedy matching in Regexps.) :-( Cheers, Martin Martin Packer, Mainframe Performance Consultant, zChampion Worldwide Banking Center of Excellence, IBM +44-7802-245-584 email: martin_pac...@uk.ibm.com Twitter / Facebook IDs: MartinPacker Blog: https://www.ibm.com/developerworks/mydeveloperworks/blogs/MartinPacker From: Ken MacKenzie <ken.macken...@pramerica.ie> To: IBM-MAIN@bama.ua.edu, Date: 06/02/2012 14:53 Subject: Regular Expressions (OMVS) Sent by: IBM Mainframe Discussion List <IBM-MAIN@bama.ua.edu> Hi All, I'm not sure if this is the appropriate forum, please point me to the correct one if it's not. 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 QQQQABCDEFGNOPQRXXXPPPPABCDEFGNOPQRYYYOOOOABCDEFGNOPQRZZZ QQQQABCDEFGNOPQRXXXPPPPABCDEFGNOPQRYYYOOOOABCDEFGNOPQRZZZ QQQQABCDEFGNOPQRXXXPPPPABCDEFGNOPQRYYYOOOOABCDEFGNOPQRZZZ QQQQABCDEFGNOPQRXXXPPPPABCDEFGNOPQRYYYOOOOABCDEFGNOPQRZZZ 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. This is being driven from a REXX exec in ISPF, if any of the above is not clear, I will try to explain further. ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: INFO IBM-MAIN Unless stated otherwise above: IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: INFO IBM-MAIN ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: INFO IBM-MAIN This e-mail may contain confidential or privileged information. If you think you have received this e-mail in error, please advise the sender by reply e-mail and then delete this e-mail immediately. Thank you. Aetna ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@bama.ua.edu with the message: INFO IBM-MAIN