Searching Source In The Twenty-First Century
October 4, 2016 Ted Holt
I love it when IBM gives me a way for me to do something I couldn’t do before. When I think of the tools I had to work with three decades ago, I could almost weep. Recently I had to search a source member for a string of characters, and I was overjoyed that LPEX gave me what SEU couldn’t. To set the stage for my requirement, I should mention that as a matter of practice, I qualify data structures in my RPG programs. For me to omit the qualified keyword, I have to have a reason. dcl-ds Status qualified; Code char(2); Text char(24); end-ds; To access a subfield of a qualified data structure requires me to prefix the subfield with the data structure name and a period. Status.Code = '20'; Status.Text = 'Operation completed'; The RPG compiler graciously allows us to leave blanks before and after the period. I assume this is for purposes of readability. At least, that’s the reason I sometimes include blanks. Status . Code = '20'; Status . Text = 'Operation completed'; How, then, do I search for all instances of the Code subfield of the Status data structure? If I look for “status.code”, the system won’t find the subfield where I left one or more blanks before or after the period. If I leave a blank here or there, the system matches the blanks in the pattern, just as it matches other characters. Fortunately, LPEX allows us to use regular expressions when we search. The regular expression in my example consists of the following pieces:
Here are a few more examples of searches using regular expressions.
You can do a lot, and I do mean a lot, with regular expressions. Regular expressions are cryptic, but they have to be cryptic in order to be so powerful. You may as well master regular expressions. They’re not going away any time soon. To learn more about regular expressions, see the links given below.
Ted Holt welcomes your comments and questions. Email him through the IT Jungle Contacts page.
RELATED STORIES Java Regular Expression Patterns Online Regular Expression Tester
|