Home >Online Product Documentation >Table of Contents >Pattern Matching
You can use regular expressions to specify match patterns for the rows in the input file. Only those rows in the input file that match the pattern you specify are output to XML when the file is converted. The simplest way to define a match pattern is to use the Match Pattern property in the Row Element Name section of the Properties window.
Consider the following input file:
If you specify a simple regular expression, say, ^B, for the Match Pattern property, Stylus Studio displays the input file in the Custom XML Conversion Editor as shown in Figure 177 - green check marks identify the rows that match the pattern, and red X's identify the rows that do not. (You can also display matching rows in a contrasting color by clicking the Highlight Matching Rows button. See Document Pane Display Features for more information about this feature.)
Note that the match pattern also appears as a new node in the schema pane. This new node, the only one defined for the custom XML conversion definition at this point, uses the default row element name (row) and the value of the expression.
Since the match pattern selects only those rows that begin with the letter B, the custom XML conversion definition creates the following XML document when it is run against the input file:
See Working with Nodes to learn about adding the row element name/match pattern pairs that define them.
The following table presents some commonly used regular expressions.
Go to http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html to learn about the specific regular expression implementation supported in Stylus Studio. Go to http://www.boost.org/libs/regex/doc/syntax.html for additional examples of regular expression usage.
You can specify multiple match patterns for a single file. If we define a new match pattern, ^K, this results in a new node (<row> "^K") in the schema pane, which now displays both nodes (see Figure 178). When an input file is converted, Stylus Studio matches the patterns in the order in which the nodes that represent them are defined in the schema. Blank patterns are always matched last.
When you define multiple match patterns, the document pane displays a gray square alongside rows that match a pattern other than the one, if any, associated with the currently selected row. In Figure 178, for example, row 3 is the currently selected row; it matches the pattern ^K we have defined. Because row 3 is the active row, Stylus Studio displays gray squares in rows 2 and 6 (which match the pattern B defined previously).
In addition to defining nodes using the Match Pattern field of the Properties window, you can also use the Set Node and Match Pattern dialog box, shown here:
This dialog box allows you to
When you open the dialog box, the Row Element Name and Match Pattern fields contain default values that reflect the currently selected row in the document pane or node in the schema pane.
When you remove a node, you are deleting the row element name/match pattern pair from the custom XML conversion you are defining.