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.
Instead, let’s use a regular expression to find the instances where Stat is followed by a digit.
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.
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
|