PeopleSoft Regular Expressions
UNIX-like Regular Expressions can be used in PeopleSoft PeopleCode by using PeopleCode support for Java. The following does a text replacement:
Local JavaObject &text; Local JavaObject &expression; Local JavaObject &converter; &text = CreateJavaObject("java.lang.String","Text to be changed"); &expression = GetJavaClass("java.util.regex.Pattern").compile("[Tt]ext"); &converter = &expression.matcher(&text); &text = &converter.ReplaceAll("Replacement");
The Java objects can be directly referenced in PeopleCode and are declared as JavaObject. The methods of the Java object can then be referenced directly.
CreateJavaObject - creates the Java String object with the text to feed to the Regular Expression then referred to by &text. This is the key to moving data from PeopleCode variables to Java objects.
GetJavaClass - refers to the Pattern Java class statically so that it can run the compile method.
This trick can be used with any Java class you want to use in PeopleCode.
Uses of Regular Expressions in PeopleCode
Checking the Format
The Custom Field Formatting of PeopleSoft is great for certain types of format checking and changing. It is ideal for reformatting phone numbers for example.
Regular Expressions however provide a large number of additional possibilities that will allow sophisticated checks to be made with a very small amount of code.
Regular Expressions also allow text processing that would take many Find, Substitute, Replace and SubString commands.
More information on Regular Expressions
Regular expression calculator: Regular Expression Calculator
Regular expression information: Regular Expression Information