| Join wMUsers | Blog at wMUsers | User Control Panel | Site Map | webMethods Jobs |For Employers |
![]() | ![]() |
![]() |
IntroductionA regular expression is a text string that describes some set of strings. Regular expressions are a pattern-matching technique supported in a variety of tools and software but are most commonly known from UNIX tools such as grep, sed, vi and emacs. Using regular expressions (regex for short) you can determine if a string matches a specific pattern. webMethods Integration Server provides regex support. The syntax and usage is described in the webMethods Developer User's Guide (Appendix D in version 4.6, Appendix B in 6.0). This webMethods Ezine article addresses using regex patterns in:
Regex in LabelsUsing regular expressions can greatly simplify your BRANCH constructs. The regular expression in a label must be surrounded with slashes. As an example, consider the common task of needing to determine if a pipeline variable contains at least one non-space character. Without using regex the FLOW steps to accomplish this might look like this:
Using a regular expression can greatly simplify the steps needed. The following FLOW steps accomplish this easily:
The following table provides a few regular expressions samples for common tasks.
regex and WQLWQL is the webMethods precursor to XQL. Both languages are supported by the query service ( This facility is described in the Working with XML Documents document shipped with v6.0 and in the Developer User's Guide with v4.6 and earlier. From an example described in the webMethods documentation, the following query:
WQL coupled with regex provides significant power and flexibility in processing XML. regex and Built-In String ServicesThere are two built-in services that support regex:
The The
In this example, "+0000" in the inString is replaced by "+" as shown by the variable named value. The search string can be described as "look at the beginning of the string for a + followed by one or more zeroes." The search string uses these regex features:
We can add some flexibility to Eric's regex example to support a optional leading + or - and keep it in the resulting value. The screen shot below again shows the results tab after running
The search string in this second example can be described as "look at the beginning of the string for an optional + or - followed by one or more zeroes." This search string uses these regex features:
As you can see, just a few characters in a regular expression can do quite a bit of work. Any regular expression can be used to search for and replace substrings. The best way to learn to use regular expressions is to play around with them. Run SummaryRegular expressions are a powerful way to easily process strings and control process flow. While they can't do everything (e.g. using regex to try to trim whitespace from all elements in an XML string would be ill-advised) they can make many tasks a breeze.
Go Deeper on the Subject: The wMUsers Discussion Forums Rob Eamon is a consultant with SBI and Company and has over 17 years experience in IT-related areas. He has completed several successful integration projects using the webMethods Platform.
Rob can be reached via email at |
| © All Rights Reserved, 2001-2008. |