PeopleSoft Regular Expressions

From TekiWiki
Revision as of 19:47, 19 January 2016 by WikiSysop (Talk | contribs) (Checking the Format)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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");

CreateJavaObject - creates the Java String object with the text to feed to the Regular Expression then referred to by &text.

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.

Text Processing

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