Regular expressions (regex) – common operators

Regular expressions are a way to define a pattern that is used to search for text strings that match the pattern. They also allow you to extract parts of the text for re-use. There are several varieties of regular expressions; CADMATIC eShare uses the regular expressions of Microsoft .NET.

[A-Z]

Matches any single uppercase letter from A to Z.

Example:

  • Matches: A, B, X, Z

  • Does not match: a, 5, -

\d

Matches any single digit from 0 to 9.

Example:

  • Matches: 0, 3, 7, 9

  • Does not match: a, -, (space)

\w

Matches any single character: a letter (A-Z, a-z), digit (0-9), or underscore (_).

Example:

  • Matches: A, b, 7, _

  • Does not match: -, (space)

{n}, {n,},{n,m}

Used to specify how many times the preceding element must appear.

Example:

  • \d{3} → Matches exactly 3 digits, e.g. 123, but not 12 or 1234

  • [A-Z]{2,} → Matches 2 or more uppercase letters in any order, e.g. AE, XYZ

  • \w{1,4} → Matches anything with 1 to 4 characters, e.g. a, ACD, A_12

| (alternation operator, OR operator, pipe)

Acts as a logical OR, matching either the pattern on the left of the character or the one on the right.

Example:

  • Pattern: AB|FL|GH

  • Matches: AB, FL, or GH

  • Does not match: BC, FF, HG

Tip:
Use parentheses to combine with other patterns.

Example:
Pattern: (AB|FL|GH)\d{3}
Matches: AB123, FL789, GH000
Does not match: AC456

^

Anchors the match to the start of the string or line.

Example:

  • Pattern: ^[A-Z]{2}

  • Matches two uppercase letters in the beginning of a string

    • Matches: AB123, FL-45

    • Does not match: 123AB, -GH

Example:

  • Pattern: ^([A-Z]{2,3}-\d{3})$

  • Matches: TT-345, PSV-529, MOV-224

  • Does not match: "PI-123 Pressure Instrument", "_TSV-447".

Main purpose is to create an attribute that has only values with a pattern strictly according to a specific naming convention.

?

Makes the preceding element optional, meaning it matches 0 or 1 occurrence of that element.

Example:

  • Pattern: \d{3}[A-Z]?

  • Matches:

    • 123A → 3 digits followed by an optional uppercase letter

    • 456 → 3 digits with no letter

Tip:
Use [A-Z]? after \d{3} when a code may or may not end with an uppercase letter, which is very typical for equipment or instruments.

.*"

Matches a double quote (") preceding any sequence of characters (including digits, spaces, or slashes).

Example:

  • Pattern: .*"

  • Matches: 1/2", 3/4", 1 1/2", 1_1/2", 1.1/2", 3", 12"

Tip:
Use .*" to capture any pipeline diameter notation that ends with a double quote, regardless of format, since it accepts fractions, mixed fractions, underscores, dots or spaces before the double quote (").

\n

Matches a line break (newline) character – used to detect or insert a new line between two parts of a string.

Example:

  • Pattern: [A-Z]{2,3}\n\d{3,4}

  • Matches:

    • PI
      2345

    • PSV
      567

  • Does not match: PI 2345 (space instead of line break)

Tip:
Use \n when instrument tags are split across two lines.
Example:
Line 1: Tag code (PI, PSV, TT)
Line 2: Number (2345, 567)

This matches multi-line identifiers in diagrams or engineering drawings. This operator is generally used in Document Handling. For more information, see Linking multiline text strings.