• 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
    ARCAD Software

    Embrace VS Code for IBM i Development

    The IBM i development landscape is evolving with modern tools that enhance efficiency and collaboration. Ready to make the move to VS Code for IBM i?

    Join us for this webinar where we’ll showcase how VS Code can serve as a powerful editor for native IBM i code and explore the essential extensions that make it possible.

    In this session, you’ll discover:

    • How ARCAD’s integration with VS Code provides deep metadata insights, allowing developers to assess the impact of their changes upfront.
    • The role of Git in enabling seamless collaboration between developers using tools like SEU, RDi, and VS Code.
    • Powerful extensions for code quality, security, impact analysis, smart build, and automated RPG conversion to Free Form.
    • How non-IBM i developers can now contribute to IBM i projects without prior knowledge of its specifics, while ensuring full control over their changes.

    The future of IBM i development is here. Let ARCAD be your guide!

    Register now!

    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

  • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
  • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
  • i-Rays Brings Observability To IBM i Performance Problems
  • Another Non-TR “Technology Refresh” Happens With IBM i TR6
  • IBM i PTF Guide, Volume 27, Number 18
  • Will The Turbulent Economy Downdraft IBM Systems Or Lift It?
  • How IBM Improved The Database With IBM i 7.6
  • Rocket Celebrates 35th Anniversary As Private Equity Owner Ponders Sale
  • 50 Acres And A Humanoid Robot With An AI Avatar
  • IBM i PTF Guide, Volume 27, Number 17

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