Named patterns

When you are creating a new rule, some entry fields allow you to use regular expressions to match text. To insert a regular expression, you must use a named pattern.

If you type wildcard characters in an entry field that allows regular expressions, these characters are taken as literals. By naming the pattern instead of using wildcard characters, you can use the matched value for the pattern in several locations, such as in the fix or in the error message.

If a field supports the use of regular expressions, the field is accompanied by an Insert Pattern button. To create a new named pattern, complete the following steps:
  1. Click Insert Pattern to open the Named Patterns dialog box.
  2. Click New Pattern to open the Create Named Patterns dialog box.
  3. In the Name field, specify a name for the new pattern that you are creating. For example, A Macros.
  4. In the Pattern field, type a valid regular expression that you want to use. For example, A.*.
    Notes:
    1. Java™ regular expression syntax is used for named patterns.
    2. It can be difficult to know if the regular expression that you specify will match the text that you want it to match. The Test section is provided to allow you to test your regular expression.
  5. In the Text field, type some sample text to test for matches against the regular expression that you specified. For example, ADD. If a match is located, Match is displayed beside Text field. If no matches are found, NO Match is displayed.
  6. Click OK to create the new named pattern and close the Create Named Patterns dialog box. After you create a pattern and assign it a name, you can insert the named pattern into entry fields.
  7. In the Named Patterns dialog box, click Insert to insert the new named pattern into the entry field.
    Tip: The Preview section displays the final value, including the inserted variables. When patterns are inserted, they are inserted using the name of the pattern, enclosed with $ characters. For example, $A Macros$.
Although you can import patterns into your rule that have already been defined for other rules, rules cannot share patterns. Instead, imported patterns are copied into the new rule. To import a pattern into your rule:
  1. Click Import to open the Import Named Pattern dialog box.
  2. From the list of available named patterns, select the named pattern that you want to import into your rule, and then click OK. The selected named pattern is added to the list of named patterns in the Named Patterns dialog box.
Notes:
  1. Text within named patterns is treated as a regular expression. Any text that is typed directly into the text field that is not within a pattern is treated as literals that must be matched.
  2. The $ character is used when specifying variable names. If you want to match a $ character in the text, create a pattern in which the regular expression is \$.

Using named patterns

You can use named patterns to do either of the following:
  • Provide a regular expression that rules can try to match when they detect problems.
  • Provide a method for referring to a matched pattern in another location.
Matched values can be used in the error message for a rule and in the fix for a rule. When a field supports the ability to add the value of a matched pattern, it is accompanied by an Insert Matched Pattern button. The value that the pattern matched for the rule is substituted in place of the pattern name when the rule is matched. For example, if a rule uses the $A Macros$ variable, then the fix description might state: Replace instruction $A Macros$ with ABC.

If the instruction that the rule matched was ADD, then the fix description might state: Replace instruction ADD with ABC.