Pattern Variables

[Previous] [Next]

When you use patterns to match sections of input data, you must first capture the data in pattern variables for later use. You assign pattern variables by using the => symbol and reference them later. For example, in the first find rule in the following program the matched input data is assigned to the found-text pattern variable.

 process submit "A [mallard] duck walks into a bar." find ("[" letter+ "]") => found-text output found-text find any 

This program outputs [mallard].

What if you want to output only the word in the square brackets, but not the square brackets themselves? Try this:

 process submit " A [mallard] duck walks into a bar." find "[" letter+ => found-text "]" output found-text find any 

This program outputs mallard. Here, the pattern variable is attached only to the part of the pattern immediately preceding the pattern variable assignment. This is the default behavior of pattern variables. That's why the previous example wouldn't work correctly unless we surrounded the three elements of the pattern with parentheses to ensure that the text matched by the whole pattern was captured.

You can have more than one pattern variable in a pattern. You can even nest them. Consider this example:

 process submit " A [mallard] duck walks into a bar." find      ("[" => first-bracket letter+ => found-word "]" => second-bracket) => found-text output first-bracket output found-word output second-bracket output found-text find any 

The output of this program would be [mallard][mallard]. The first "[mallard]" is the result of the first three output actions; the second "[mallard]" is the result of the fourth output action.



XML and SOAP Programming for BizTalk Servers
XML and SOAP Programming for BizTalk(TM) Servers (DV-MPS Programming)
ISBN: 0735611262
EAN: 2147483647
Year: 2000
Pages: 150

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net