Quantification Using Metacharacters
- Last UpdatedMar 28, 2024
- 4 minute read
A quantifier after a character or group defines how often the preceding element may occur.
The most commonly used quantifiers are ?, *, and +.
-
? The question mark indicates there is zero or one of the preceding element. For example, too? matches both to and too.
-
* The asterisk indicates there are zero or more of the preceding element. For example, ab*c matches ac, abc, abbc, abbbc, and so on.
-
+ The plus sign indicates that there is one or more of the preceding element. For example, ab+c matches abc, abbc, abbbc, and so on, but not ac.
The following table contains explanations of the meaning of some commonly used Regular Expression metacharacters, and provides some simple examples of their use, to define how Schematic Model Manager may automatically determine the GTYPE and optionally the SCSTYPE that should be applied to an ISO15926 component class when executing the 'Auto Complete' option.
|
Meta- |
Description |
Example |
|---|---|---|
|
. |
Matches any character except a newline. If used inside square brackets then the dot is treated as a literal. |
Example: (3.*(WAY VALVE)) What this expression means: Matches any component class which contains with any two characters (including space) followed by "WAY VALVE" Example matches using expression: 3 WAY VALVE |
|
( ) |
Groups a series of pattern elements to a single element |
Example: ((BLI..).(SP...)) What this expression means: Matches any component class which contains BLI followed by any 2 characters followed by any 1 character followed by SP followed by any three characters. Example matches using expression: BLIND SPADE |
|
+ |
Matches the preceding pattern element one or more times. |
Example: (CLOSED.4+) What this expression means: Matches any component class name which contains CLOSED followed by any character followed by 4. Example matches using expression: CLOSED 4 WAY VALVE |
|
? |
Matches the preceding pattern element zero or one times. |
Example: (CLOSED.4?) What this expression means: Matches any component class name which contains CLOSED followed by any character and optionally followed by 4. Example matches using expression: CLOSED 4 WAY VALVE CLOSED VALVE |
|
* |
Matches the preceding pattern element zero or more times. |
Example: (4.*WAY VALVE) What this expression means: Matches any component class name which contains 4 followed by zero or one characters followed by WAY VALVE Example matches using expression: 4WAY VALVE 4 WAY VALVE |
|
{M,N} |
Denotes the minimum M and the maximum N match count. |
Example: X{1,1} What this expression means: Matches any component class name which contains one and only one X Example matches using expression: FLEXIBLE HOSE |
|
[...] |
Denotes a set of possible character matches. |
Example: [123] What this expression means: Matches any component class name which contains 1,2 or 3 Example matches using expression: 1 WAY VALVE 2 WAY VALVE DIAPHRAGM ACTUATED 3 WAY BALL VALVE |
|
[n1-n2] |
Matches a range of characters (alpha and numeric), where n1 is the start of the range and n2 the end. |
Example: [1-3] What this expression means: Matches any component class name which contains a character within the range 1 to 3 Example matches using expression: 1 WAY VALVE 2 WAY VALVE DIAPHRAGM ACTUATED 3 WAY BALL VALVE |
|
| |
Separates alternate possibilities. |
Example: (SELF ACTING|AUTOMATIC) What this expression means: Matches any component class name which contains SELF ACTING or AUTOMATIC Example matches using expression: SELF ACTING GLOBE VALVE AUTOMATIC GLOBE VALVE |
|
\b |
Matches a word boundary. |
Example: (AP)\b What this expression means: Matches any component class name which contains a word ending in AP Example matches using expression: FLAME TRAP END CAP |
|
\W |
Matches a non- alphanumeric character. |
Example: \W What this expression means: Matches any component class name which contains a non alphanumeric character such as a space Example matches using expression: Any component class name which contains a non alpha numeric character |
|
\s |
Matches a whitespace character (space, tab, newline, form feed) |
Example: 3\s What this expression means: Matches any component class name which contains a 3 followed by a whitespace character Example matches using expression: 3 WAY VALVE DIAPHRAGM ACTUATED 3 WAY VALVE |
|
\S |
Matches anything BUT a whitespace. |
Example: 2\S What this expression means: Matches any component class name which contains a 2 followed by any non whitespace character Example matches using expression: 2WAYVALVE CLOSED2WAYVALVE |
|
\d |
Matches a digit, same as [0-9]. |
Example: \d What this expression means: Matches any component class name which contains a single digit Example matches using expression: PISTON ACTUATED 4 WAY VALVE CLOSED 3 WAY VALVE |
|
\D |
Matches a non-digit. |
What this expression means: Matches any component class name which contains a non digit |
|
^ |
Matches the beginning of a line or string. |
Example: ^(PISTON) What this expression means: Matches any component class name which begins with PISTON Example matches using expression: PISTON ACTUATED 4 WAY VALVE PISTON ACTUATED GENERAL VALVE |
|
$ |
Matches the end of a line or string. |
Example: (FILTER)$ What this expression means: Matches any component class name which ends with FILTER Example matches using expression: INLINE BASKET FILTER INLINE FILTER |
|
\A |
Matches the beginning of a string (but not an internal line). |
For the purposes of component class mapping this is equivalent to ^ |
|
\Z |
Matches the end of a string (but not an internal line). |
For the purposes of component class mapping this is equivalent to $ |
|
[^...] |
Matches every character except the ones inside brackets. |
What this expression means: Allows a component class to be selected based on a list of excluded characters. |