• 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
    New Generation Software

    FREE Webinar:

    Creating Great Data for Enterprise AI

    Enterprise AI relies on many data sources and types, but every AI project needs a data quality, governance, and security plan.

    Wherever and however you want to analyze your data, adopting modern ETL and BI software like NGS-IQ is a great way to support your effort.

    Webinar: June 26, 2025

    RSVP today.

    www.ngsi.com – 800-824-1220

    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

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

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 © 2025 IT Jungle