• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Replacing Source in The Twenty-First Century

    October 18, 2016 Ted Holt

    In Searching Source in The Twenty-First Century, I introduced the use of regular expressions for searching within a source member. Searching is great, but sometimes you need to replace what the system finds with something else. Here’s how to replace text when using regular expressions.

    Let’s begin with a source member.


    Notice that there are nine constants named Stat10 through Stat90. Let’s replace
    Stat with Status_. Obviously we can’t replace Stat with Status everywhere it’s found. That would be disastrous!

    Instead, let’s use a regular expression to find the instances where Stat is followed by a digit.


    I clicked on the “All” button so that LPEX shows me only the lines that contain the search string.

    Now it’s time to replace, but what is the replacement string? If I replace the matched characters with Status_, the digit will be obliterated, and I don’t want that. What I want to do is to replace that digit with itself, and to do that, I use a capturing (or capture) group.


    In the Find box, I enclose \d in parentheses to indicate that whatever matches this piece of the search string is to be saved in the first capturing group. In the Replace box, I use the expression $1 to indicate the place where LPEX is to use the first capturing group. This expression replaces
    Stat with Status_ and the digit that follows Stat with itself.

    Using regular expressions to search and replace text is like a multitude of other things you’ve done. Once you do it a few times, you’ll wonder why you ever thought it was hard.

    Ted Holt welcomes your comments and questions. Email him through the IT Jungle Contacts page.

     

    RELATED STORY

    Searching Source in The Twenty-First Century

     

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: FHG, Four Hundred Guru

    Sponsored by
    Computer Keyes

    Create Full Color Overlays, Interactive PDFs

    KeyesOverlay rapidly converts standard *SCS printer files into eye-catching PDF documents. Create graphical overlays in full color (or black and white if preferred) then easily map your spooled file text with different fonts, sizes and colors!

    KeyesOverlay can also create Interactive Forms for your customers to fill out and email or submit back to you.

    www.computerkeyes.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Chrono-Logic:  Deploy automatically to multiple IBM i and Windows servers with a single click!! Fresche:  IBM i staffing for all of your IT needs. Request a FREE estimate. 1-800-361-6782 Manta Technologies Inc.:  The Leader in IBM i Education! Download catalog and take sample sessions!

    Mobile Apps As Easy As RPG III On Your IBM i Radar Now: GDPR

    Leave a Reply Cancel reply

Volume 16, Number 23 -- October 18, 2016
THIS ISSUE SPONSORED BY:

T.L. Ashford
WorksRight Software
Focal Point Solutions Group

Table of Contents

  • A Style Guide for Modern RPG and ILE, Part 2
  • Replacing Source in The Twenty-First Century
  • SQL PL Conditional Structures

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Power10 Entry Machines: The Power S1024 And Power L1024
  • Thoroughly Modern: Latest IT Trends – Bring Security, Speed, And Consistency To IT With Automation
  • Big Blue Unveils New Scalable VTL For IBM i
  • As I See It: Thank God It’s Thursday
  • IBM i PTF Guide, Volume 24, Number 32
  • JD Edwards Customers Face Support Decisions
  • Security, Automation, and Cloud Top Midrange IT Priorities, Study Says
  • Cleo and SrinSoft in Integration-Modernization Link Up
  • Four Hundred Monitor, August 3
  • IBM i PTF Guide, Volume 24, Number 31

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2022 IT Jungle

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.