Views

Regular expressions

Regular expressions (regex for short) are search patterns. They find variants without you having to enter every spelling separately.

They are available in two places: as the operator Regular Expression in the detailed search and as the change type Preg Replace in bulk edit .

How Moliri evaluates them

Matches are treated like a Contains search: the pattern has to occur somewhere in the value, not cover the whole value. So 18\d{2} finds every occurrence of 18 followed by two digits, even in the middle of a description.

In the detailed search, the database evaluates the pattern; a pattern it cannot evaluate is rejected. In bulk edit, JavaScript syntax applies. The expressions in the following table work in both places.

Syntax

ExpressionMeaning
.Any character except a line break
^Start of the line
$End of the line
*0 or more repetitions of the previous character
+1 or more repetitions
?0 or 1 repetition (optional)
{n}Exactly n repetitions
{n,}At least n repetitions
{n,m}Between n and m repetitions
\dA digit (0-9)
\DNot a digit
\wA word character (a-z, A-Z, 0-9, _)
\WNot a word character
\sA space, tab or line break
\SNot a space
[abc]One of the characters a, b or c
[^abc]None of the characters a, b or c
[a-z]Any character from a to z
[0-9]A digit from 0 to 9
(abc)Group; can be reused in replacements as $1, $2 …
(?:abc)Group without reuse
\|OR. Apfel\|Birne finds Apfel or Birne
\. \( \/Search for a special character literally

Why this helps with collection data

Museum collections are inconsistent, because they have grown over decades and from different sources. Regular expressions help with the typical results of that: different spellings of the same name, different separators in numbers, and numbers that sit in free text and so cannot be compared with greater than or less than.

Examples

Artist’s name in different spellings

Claude Monet|C\.? Monet|Monet, Claude

Finds Claude Monet, C. Monet, C Monet, Monet, Claude.

Title with and without a hyphen

Still[- ]?leben

Finds Stillleben, Still-Leben, Still Leben.

Years in a free-text field

18\d{2}

Finds 1805, 1832, 1899, even in the middle of a sentence. This is the only way to reach dates in descriptive texts, where a greater-than or less-than comparison does not work.

Material details with variants

Öl auf (Leinwand|Holz)|Ölgemälde

Inventory numbers with changing separators

\d{3}[-/.]\d{3}

Finds 123-456, 123/456, 123.456.

Values that must match a pattern exactly

^INV \d{4}/\d{4}$

With ^ and $ the Contains effect is cancelled, and the expression has to cover the whole value.

Finding double spaces

\s{2,}

Together with the change type Collapse whitespace in bulk edit, this is the tool for tidying up imported texts.

In bulk edit

Preg Replace also takes options (such as g for all occurrences, i for ignoring upper and lower case) and a replacement value in which groups can be reused as $1:

GoalPatternOptionsReplacement
1990 - 2000 → 1990-2000(\d{4})\s*-\s*(\d{4})g$1-$2
Müller, Anna → Anna Müller^(\w+), (\w+)$$2 $1
Remove additions in brackets\s*\([^)]*\)g(empty)
Check first, then apply

A replacement by regular expression across hundreds of objects has a wide reach and is hard to undo. Before applying, bulk edit shows a preview for each object with the differences highlighted. Read this preview rather than clicking it away. See Bulk edit .