RegEx A regular expression (RegEx) is a formal pattern language used to define and recognize strings within text. It allows precise searching, validating, extracting, and transforming text data based on declarative pattern rules instead of fixed literals.

Regular expressions are supported in many programming languages and tools (e.g., GuiXT, JavaScript, VB) and are commonly used for the following tasks:

  • Pattern matching: Identifying substrings that match a specific format
  • Validation: Ensuring input meets predefined criteria (e.g., email addresses, phone numbers)
  • Text extraction: Capturing structured data from unstructured text
  • Search and replace: Modifying text based on pattern-based rules
GuiXT Supported Commands with Regex: Set,ReadRow
RegEx Syntax
Regular expressions (RegEx) are a "special search language" for text. Instead of searching for exact words, RegEx uses patterns to find, validate, or extract text.

1. Letters and Characters

Normal characters match themselves. Example:

cat → matches "cat" in "my cat is cute"

Normal characters are all UTF‑8 characters except the following 14 metacharacters: . ^ $ * + ? ( ) [ ] { } | \ These metacharacters have special meanings, which will be explained in the following sections.

2. Special Characters

Symbol Meaning Example
. Any single character except line break a, 1, #
\d Any digit (0–9) 3, 7
\D Any character that is not a digit a, #
\w Letter, digit, or underscore A, z, 5, _
\W Any character that is not a word character !, @, #
\s Whitespace (space, tab, line break) , \t, \n
\S Any character that is not whitespace a, 1, #

3. Quantifiers

Symbol Meaning Example
* 0 or more repetitions a*, matches "", "a", "aaa"
+ 1 or more repetitions a+, matches "a", "aa"
? 0 or 1 repetition a?, matches "" or "a"
{n} Exactly n repetitions \d{2}, matches "12", "99"
{n,} At least n repetitions \d{2,}, matches "12", "420", "1337"
{n,m} Between n and m repetitions a{1,3}, matches "a", "aa", "aaa"

4. Character Classes

  • [abc] → matches "a", "b", or "c"
  • [^abc] → matches anything except "a", "b", or "c"

5. Anchors

  • ^ → start of string, e.g., ^Hello matches "Hello" in "Hello world" but not in "world Hello"
  • $ → end of string, e.g., world$ matches "world" in "Hello world" but not in "world Hello"

6. Groups and OR

  • (abc) → capture group for "abc"
  • | → OR operator, e.g., cat|dog matches "cat" or "dog"

7. Word Boundaries

\b ensures the match is a whole word:

\bcat\b matches "cat" in "my cat" but not "caterpillar"

8. ECMAScript‑Style Replacement Syntax

When using RegEx replacements in GuiXT, special replacement tokens allow you to insert parts of the matched text or captured groups.

Token Meaning Example
$& The entire matched text "cat" → replaced with "[$&]" becomes "[cat]"
$` Text before the match "hello cat world" → "$`" gives "hello "
$' Text after the match "hello cat world" → "$'" gives " world"
$n Captured group number n (1–99) Pattern: (\w+)-(\w+)
Replace: $2-$1
$$ Literal dollar sign "Price: $" → replaced with "$$" becomes "Price: $"

These tokens follow the ECMAScript Regular Expression Specification and are widely used in GuiXT, JavaScript and many tools that rely on ECMAScript regex behavior.

9. Escaping Characters

Some characters in RegEx have special meanings (such as ., *, +, ?, $, ^, [ ], ( )). If you want to match these characters literally, you must escape them using a backslash (\).

Example:

file\.txt → matches "file.txt" (the dot is treated as a literal dot, not "any character")

Without escaping, file.txt would also match strings like "file1txt" or "fileAtxt", because . normally means "any character".

Examples GuiXT provides many ways to use RegEx, e.g., with regex=, regexReplace=,
regexReplaceFirst=
as options for certain keywords.

Pattern Validation: Date

GuiXT
// This RegEx checks whether the string matches our date format
// It does not check if it is a valid date!
Set V[x]   "12.12.2026"  regex="^\d{2}\.\d{2}\.\d{4}$"
// Use if Q[ok] to verify if our string matches the pattern
if Q[ok]
  Message "Success!"
else
  Message "Invalid format!"
endif

Text Extraction

GuiXT
// Extracts M02 from our text
Set  V[x]   "Abc .M02. ..."  regex="\bM02\b"
Message "&V[x]" // msg: M02
// Extracts V + two digits from our text
Set  V[x]   "Abc .V02. ..."  regex="\bV\d{2}\b"
Message "&V[x]" // msg: V02
// Extracts any letter + 2 digits from our text
Set  V[x]   "Abc .Y02. ..."  regex="\b[A-Za-z]\d{2}\b"
Message "&V[x]" // msg: Y02

Text Replacement

GuiXT
// Replaces all occurrences of M02 in the string with V02
Set  V[x]   "Abc .M02. ... -a.b,c. M02"  regex="\bM02\b" _
regexReplace="V02"
Message "&V[x]" // msg: Abc .V02. ... -a.b,c. V02
// Replaces the first occurrences of M02 in the string with V02
Set  V[x]   "Abc .M02. ... -a.b,c. M02"  regex="\bM02\b" _ 
regexReplaceFirst="V02"
Message "&V[x]" // msg: Abc .V02. ... -a.b,c. M02
// Replaces all occurrences that match the pattern 
// letter + 2 digits with ---
Set  V[x]   "Abc .AM02. ... -a.b,c. G05... .. O10" _
regex="\b[a-zA-Z]\d{2}\b" regexReplace="---"
Message "&V[x]" // msg: Abc .AM02. ... -a.b,c. ---... .. ---

Dynamic Regex

Regular expressions (RegEx) use certain characters with special meanings to define matching behavior.
Because of this, any user-provided input should be properly sanitized before being used in a RegEx pattern.
For example, when searching for a date such as 12.12.2022, the dot (.) is interpreted in RegEx as a wildcard that matches any character.
This would unintentionally allow matches like 12a12b2022 instead of only the exact date format.
To ensure the dots are treated as literal characters, they must be escaped using a backslash (\).
The correct RegEx pattern would therefore be: 12\.12\.2022 By escaping special characters, the expression behaves as intended and matches only the exact input format.
 GuiXT
// Clears the screen
del (0,0) (20,200)
// We define our test InputFields and Box
Box	(8,59)	(17,101)	"RegEx Test"
// This InputField takes what we want to search
InputField	(10,60)	"Input"	(10,70)	size=20	name="input"
// This InputField takes a text that we search in
InputField	(12,60)	"Text"	(12,70)	size=30	name="text"
// And then we call a InputScript DynamicRegEx
// and pass our field Values
Pushbutton	(14,61)	"Test" "?" process="DynamicRegEx.txt" _
"&V[input]" "&V[text]"
GuiXT (DynamicRegEx)
// Define the parameters we expect to receive
Parameter input
Parameter text
// Sanitize the input by escaping all special regex characters
// This prevents unintended behavior or errors 
// When the string is used in a regular expression
Set V[clean] "&V[input]" regex="([\\.^$+(){}\[\]|?*])" _
regexReplace="\$&"

// If no special characters were found, Q[ok] is false
if not Q[ok]
  // In that case, simply return the original input unchanged
  // If special characters were found, 
  // V[clean] already contains the escaped version
  Set V[clean] "&V[input]"
endif

// Now we can use the sanitized input for our search
// in this case we simply replace all found words
// with +found+
Set V[Message] "&V[text]" regex="&V[clean]" _ 
regexReplace="+found+"
// And finally we output our string
Message "&V[Message]"

Examples for ReadRow can be found here.

Reference Guide A great way to test regular expressions is the website RegExr,
where you can try your RegEx in real time and see what it does.
Pattern Meaning Example
. Matches any single character except line break a, 1, #
\d Matches any digit (0–9) 3, 7
\D Matches a non-digit character a, #
\w Matches a word character (letter, digit, underscore) A, z, 5, _
\W Matches any non-word character !, @, #
\s Matches whitespace (space, tab, line break) , \t, \n
\S Matches any non-whitespace character a, 1, #
[abc] Matches a character from the set (a, b, or c) a, b, c
[^abc] Matches a character not in the set d, 1, #
a* Matches zero or more repetitions of "a" "", "a", "aaa"
a+ Matches one or more repetitions of "a" "a", "aa"
a? Matches zero or one repetition of "a" "", "a"
{n} Exactly n repetitions \d{2} → "12", "99"
{n,} At least n repetitions \d{2,} → "12", "420"
{n,m} Between n and m repetitions a{1,3} → "a", "aa", "aaa"
^ Matches the start of the string ^Hello → "Hello world"
$ Matches the end of the string world$ → "Hello world"
(abc) Capture group for "abc" "abc" in "abc123"
| Logical OR between patterns cat|dog → "cat" or "dog"
\b Word boundary (whole word match) \bcat\b → matches "cat" but not "caterpillar"
$& Entire matched text "cat" → "[$&]" becomes "[cat]"
$` Text before the match "hello cat world" → "hello "
$' Text after the match "hello cat world" → " world"
$1 … $99 Captured group number (\w+)-(\w+) → "$2-$1"
$$ Literal dollar sign "Price: $" → "$$"