Tue 27 Sep 2005
Bringing the power of Regular Expressions to PeopleCode
Posted by ChiliJoe under PeopleSoft • Tips & Techniques • PeopleCode1 Comment
Regular expressions (or regex as it is affectionately called) is a powerful tool for searching (and also, replacing) complex text patterns. A quick tutorial can be found at www.regular-expressions.info.[1] To quote from that site:
If you are a programmer, you can save yourself lots of time and effort. You can often accomplish with a single regular expression in one or a few lines of code what would otherwise take dozens or hundreds.
In addition to that argument, writing your own implementation with dozens of lines of code also makes it prone to defects, and makes it more difficult to maintain. And if the required pattern is changed slightly, the impact on your code could be very huge, or even require a rewrite of your custom implementation. With regex, what is often required is to change a few characters in the pattern.[2]
PeopleCode do not have an implementation of regular expressions, but fortunately, it is easy to utilize Java objects from PeopleCode. Note that regex capabilities was only added to Java since version 1.4.