14.3. Regular expression

With regular expressions certain sections of column values can be identified via a combination of signs.

Example:

The column values of the variable standard number consist of complex character strings (e.g. "xyz DIN 174jdfjd"). The expressions for the standard number in the PARTdataManager tables ("DIN 174") are "hidden" within these character strings in various places. In order to be able to compare the column values of the text file and the table, the relevant expressions must be "extracted" from the character strings.

Solution:

Expression "DIN [0-9] * " .

This filters out the following string: "DIN", followed by a space and a number. The number consists of the digits 0 to 9, which can appear as often as you like in this number.

Characters [Symbol] used in connection with regular expressions:

Characters in regular expressions

Description

* (star)

The character or character string to the left of the asterisk can occur as often as required or not at all.

+ (Plus)

The character or character string to the left of the plus sign can occur any number of times, but at least once.

? (question mark)

The character or character string to the left of the question mark can occur either once or not at all

. (point)

The dot stands for any character that occurs once.

[ ^] (hood with brackets)

Characters inside the brackets and behind the hood are excluded.

^ (hood without brackets)

Characters preceded by a cap must be at the beginning of a character string.

$ (dollar sign)

Characters followed by a dollar sign must be at the end of a character string.

\ (backslash)

A preceding backslash cancels the function of characters in regular expressions.

Possible regular expressions:

The basis is the character string ABCXYZDEF

Expression

Description

Example

XYZ

Reads out X and Z , as well as the defined expression between X and Z

ABC XYZ

X . Z

Reads X and Z , as well as any character between X and Z

ABC XAZ

ABC XeZ

ABC X4Z

etc.

X .* Z

Reads X and Z , as well as any character (occurring any number of times) or no character between X and Z.

ABC XZ

ABC XAZ

ABC XApZ

etc

X .+ Z

Reads X and Z , as well as any character (any number of times, but at least once) between X and Z .

ABC XAZ

ABC XrGZ

etc

X .? Z

Reads out X and Z , as well as any character or no character between X and Z.

ABC XZ

ABC XAZ

ABC X8Z

etc

XA + Z

Reads out X and Z , as well as A (any number of times, but at least once) between X and Z .

ABC XAZ

ABC XAAZ

ABC XAAAZ

etc

XA ? Z

Reads out X and Z , as well as A once or not between X and Z

ABC XZ

ABC XAZ

X[AB] * Z

Reads out X and Z , as well as any combination ofAand B or no character between X and Z.

ABC XZ

ABC XAZ

ABC XBZ

ABC XABZ

ABC XBAZ

ABC XAAZ

ABC XBBZ

ABC XABAZ

ABC XBBAABAZ

etc

X[ ^ AB ]Z

Reads X and Z, as well as any combination of characters between X and Z, with the exception of the characters A and B .

ABC X AB Z

Expression

Description

Example

X[A-C]Z

Reads out X and Z, and either A, B or C between X and Z

ABC XAZ

ABC XBZ

ABC XCZ

X[0-9] * Z

Reads out X and Z , as well as any combination of numbers or no character between X and Z.

ABC XZ

ABC X0Z

ABC X1Z

ABC X6372Z

etc

X[A-Z][a-z] * Z

Reads out X and Z , as well as string, starting with an upper case letter and continuing with lower case letters (occurring any number of times) or no character between X and Z .

ABC XZ

ABC XAZ

ABC XAaZ

ABC XAgsagZ

ABC XBZ

etc

^ ABC

Reads defined expression if it is at the beginning of the string.

ABC

Not for:

XABCZDEF

ABC $

Reads out the defined expression if it is at the end of the character string.

XYZDEF ABC

Not for:

ABCXYZDEF

X \. Z

Cancels the function of the dot within the regular expression, so that a dot ( $ , ^ , etc. and also the backslash itself!) can also be read from a character string.

ABCX . ZDEF