Table of Contents: User and Administrator Guide : Mashup Center 22.214.171.124
Use the Regular expression function to apply a regular expression to an element. A regular expression lets you match a pattern in a set of strings, and only return the strings that match that pattern.
MashupHub uses the Java regular expression syntax for the Regexp function.
For information about regular expressions see the Regular expression syntax
topic from the WebSphere® Message Broker information center: http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r0m0/topic/com.ibm.etools.mft.doc/ad09880_.htm
For the Value
for each parameter you can:
- Specify a text value.
- Specify a function value.
- Use a variable to return the value.
- Specify a value from the Input tree.
Specify the regular expression.Input
Specify the value that you want the regular expression to be applied to. Index
This is a number that corresponds to the part of the expression that contains the value that you want returned:
- To return the entire result of the expression, specify 0
- To return a value that corresponds only to the first group that is specified in the expression, specify 1
- To return a value that corresponds only to the second group that is specified in the expression, specify 2
If you specify an Index that is greater than the number of groups that are specified in the expression, an error is returned.
This function returns a single String value.
Example - Building an expression and using groups
From the following text string, you want to extract just the city name:
Snow Advisory - Hamilton (New York)
The regular expression must find all of the characters between the dash and the open parenthesis. Start with a basic regular expression to remove some portions of the string that you do not want returned. The parenthesis have a special purpose in regular expressions, so to find the open parenthesis character in a string, you must qualify, or escape, the open parenthesis character. You escape a character by placing a forward slash character immediately before the character that you want to escape.
When you run this expression, you get this result:
You have eliminated much of the string. To return just the city name, you need to add to the expression by specifying a group for the characters that comprise just the city name:
Parentheses have a special purpose in regular expressions. The (.*)
part of the regular expression is special syntax that lets you group all the characters that comprise city together so that you can reference the group. When you run this expression, the value returned depends on the Index Value that you specify:
|Index Value||Returned value||Explanation|
|0||- Hamilton (||This index consists of the characters that are matched. In this example, the matched characters start with the dash and end with the last open parenthesis.|
|1||Hamilton||This index consists of the characters that are in the first group. In this example, the matched characters start after dash and end before the last open parenthesis.|
If you want to match both the city name and the state name, you must specify the names in separate groups in your expression. For example:
When you run this expression, you have three index values:
|Index Value||Returned Value|
|0||- Hamilton (New York)|
Example - Using multiple groups in expressions
You can specify multiple groups in an expression. For example, if the element contains names such as Anita Salinas
, you can specify an expression with two groups, one for the first name and one for the last name.
|Input data||Sample data||Expression|
When you run this expression, specify the Index value to return the data the you need:
|Index Value||Returned Value|
Parent topic: Functions : Mashup Center 126.96.36.199
Functions : Mashup Center 188.8.131.52