Skip to content

Regular Expressions

X4D Data Import uses .NET (C#) regular expressions to recognise and clean tags. A basic understanding of regular expressions is highly recommended before creating:

  • Tag Patterns
  • Split Characters
  • Text Replacement (Substitution) Expressions

Tip

Test and refine expressions at https://regex101.com using the .NET (C#) flavor, so they behave exactly as they will inside X4D.

Cheat sheet

Basics

Expression Matches
. Any character except a newline
^ Start of a string
$ End of a string
\ Escapes a special character (e.g. \. matches a literal dot)

Character classes

Expression Matches
[abc] a, b, or c
[^abc] Anything except a, b, or c
[a-z] Any lowercase letter
[A-Z] Any uppercase letter
[0-9] Any digit
[a-zA-Z0-9_] Any word (alphanumeric) character

Quantifiers

Expression Meaning
* 0 or more (greedy)
+ 1 or more (greedy)
? 0 or 1 (optional)
{n} Exactly n times
{n,} At least n times
{n,m} Between n and m times

Grouping & alternation

Expression Meaning
(abc) Capturing group
(?:abc) Non-capturing group
a\|b Matches a or b

Assertions (lookarounds)

Expression Meaning
(?=abc) Positive lookahead — abc follows (not consumed)
(?!abc) Negative lookahead — abc does not follow
(?<=abc) Positive lookbehind — abc precedes
(?<!abc) Negative lookbehind — abc does not precede

Anchors, boundaries & escapes

Expression Meaning
\b / \B Word boundary / not a word boundary
\d / \D Any digit / any non-digit
\w / \W Any word character / any non-word character
\s / \S Any whitespace / any non-whitespace

Common examples

Pattern Matches
^\d{3}-\d{2}-\d{4}$ A fixed numeric pattern (e.g. 123-45-6789)
https?://\S+ A URL
\b\d{3}-\d{3}-\d{4}\b A phone-style number (e.g. 123-456-7890)

Text substitution

Substitutions replace matched text using capture groups (\1, \2, …). For example, a pattern (\d{3})-(\d{2})-(\d{4}) with replacement \3-\1-\2 reorders the three groups.

Use substitution to correct typos and inconsistencies in source data before tags are generated (see Tag Patterns for where substitutions are applied).

Note

Add a screenshot of the X4D Text Substitution screen and project-specific examples.