MicroStation CONNECT Edition Help

Regular Expressions for Searching Text

Regular expressions consist of patterns that can be used to search for variable forms of text. Without regular expressions, you must know the exact phrase for which to search; regular expressions allow you to find all text that follows a certain pattern. Even if the Regular Expressions check box in the Find/Replace dialog is on, you can still search for exact phrases. In such a case, you have to remove the regular expression operators from the phrase (see Syntax).

Syntax of Regular Expressions for Searching Text

Regular expressions generally consist of some constant text, and some restrictions or wildcards on the rest of the text. If you want to use one of these operators as literal text, you must precede the character with a backslash.

The following is a list of regular expressions used only for searching text. When searching text, you can also use regular expressions that are used for all types of operations.

Character Meaning
[ ] Characters within these brackets describe a character class, or a custom wildcard.
* The preceding character (or character class) is allowed to repeat zero.
+ The preceding character (or character class) must repeat at least once.
- When used within a character class, represents a character range.

Examples of Regular Expressions for Searching Text

  1. Find a line that starts with "A" and ends with "2":
    ^A.*2$
      “^A” Line must start with an A
      “.*” Zero or more characters (any character)
      “2$” Line must end with a 2
    Samples:
      Abc-12 Found
      A2 Found
      1Abc-12 Not found (line does not start with A)
      Abc-123 Not found (line does not end with 2)
  2. Find text that contains the word "Plan," followed by optional space and a 4-digit number:
    Plan *:d:d:d:d
      “Plan” The literal word ‘Plan’ must start the phrase
      “ *” (space character followed by *) Zero or more space characters
      “:d:d:d:d” Any four digits
    Samples:
      My Plan1234 Found
      Plan 1234 Found
      My Plan 123a Not found (only 3 digits follow Plan)
  3. Find text that contains the characters ' [# ' but is not followed by a 1, 2, 3, 4, or B:
    \[#[^1-4B]
      “\[” The literal character [ (must be escaped)
      “#” The literal character # (not an operator, does not need to be escaped)
      “[^” Starts a character class, meaning any character but those described in the class
      “1-4B” Range 1-4 (1, 2, 3, 4) and B
      “]” Ends the character class
    Samples
      Part [#9778C] Found
      Lot [#554] Found
      Part #977 Not found (# not preceded by [)
      Part [#155A] Not found (# followed by 1)
  4. Find a line that starts with "Detail," followed by one or more spaces, followed by one or more alphanumeric characters, and a Z:
    ^Detail +:n+Z
      “^Detail” Line must start with Detail
      “ +” (space character followed by +) One or more space characters
      “:n+” One or more ASCII alphanumeric characters
      “Z” The literal character Z
    Samples:
      Detail 143Z Found
      Detail AABZ Found
      Plot A Detail 3Z Not Found (line does not start with Detail)
  5. Find currency values in the form $#,###.## :
    \$[0-9,]+\.:d:d
      \$ Match must start with a dollar sign
      [0-9,]+ Matches one or more digits or commas
      \. Followed by a decimal point
      :d:d Followed by exactly two digits
    Samples:
      $12.34 Found
      $12,123.00 Found
      12,435.00 Not found (does not start with $)
      $12 Not found (does not end with a decimal point and two digits)