Introduction
A 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:
- The label property of a child step within a BRANCH
- webMethods Query Language (WQL) statements
- Built-in String Services
Regex in Labels
Using 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:
|
regex and WQL
WQL is the webMethods precursor to XQL. Both languages are supported by the query service (pub.xml:queryXMLNode
in v6.0, pub.web:queryDocument
in v4.6 and earlier). WQL supports using regex to specify a pattern-matching string to select members of an element array.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:
- doc.bitterrootboards['*Pro Series*'].text
regex and Built-In String Services
There are two built-in services that support regex:pub.string:lookupTable
pub.string:replace
pub.string:lookupTable
service can use a regular
expression to perform a lookup on the table. It returns the first value
in the table whose key matches the specified regex pattern.The
pub.string:replace
service supports using a regular expression as the search string. Erik Versteijnen provided an example in the webMethods Discussion Forums post to strip leading zeroes from a number. The screen shot below is the results tab after running pub.string:replace.- The ^ specifies that the pattern must be at the start of the inString.
- The + character has a special meaning in regex. For this pattern we want to use the + character literally. The \ escapes the + telling the regex engine to use + as a literal rather than a regex operator.
- The 0 is used literally. The second + character is a regex operator indicating that the preceding element (in this case the character 0) can occur 1 or more times.
pub.string:replace
with the indicated parameters. Note the differences in the searchString parameter in this example as compared to the first example.- The ^ specifies that the pattern must be at the start of the inString.
- The parentheses indicate a subexpression that can be used as a substitution variable in the replacement string. In this case, any leading + or - will be placed where $1 appears, so the resulting value will have the same leading sign as the input string. If there is no leading sign, then the resulting value will not have a leading sign.
- The brackets indicate a character set. The set here is the + and the - characters. The \ escapes the + (since it is a regex operator character and we want to use it literally).
- The ? is a regex operator which indicates that the preceding item can occur zero or one times. The preceding item in this case is a character set, so the pattern will match only if one of the characters from the set appears in inString.
- The 0 is used literally. The second + is a regex operator indicating that the preceding element (in this case the character 0) can occur 1 or more times.
The best way to learn to use regular expressions is to play around with them. Run
pub.string:replace
directly in Developer to learn the basics and expand your regex abilities.
very thanks sir
ReplyDeleteThanks for your Quality information the product developed by the company is perfect.............................Please Contact us we are giving best training on Oracle Fusion Procurement Course
ReplyDeleteGreat post . thanks for sharing a clear step by step process on getting in the nice.
ReplyDeleteservice now administration training
job support
ReplyDeleteVery Nice Article…..thank you for sharing
Selenium Online Training
ReplyDeleteYour content is very impressive and thanks for sharing this article. its very useful.
best post.
ReplyDeletemulesoft training
web methods training
thanks sharing https://snowflakemasters.in/
ReplyDelete