Skip Navigation LinksAbout > User Guide > Batch Editing > Global Editing > Regular Expressions

Regular Expressions



Overview

A Regular Expression, also referred to as a RegEx, is a powerful tool that enables pattern-matching, substituting, and deleting text. Think about them as a supercharged wildcard search.

BestMARC supports RegEx patterns in Conditions and the Find & Replace command.

The following are common RegEx elements supported by BestMARC. A full reference as well as links to RegEx testers and tutorials can be found via links in the Additional Information section.

Note: Some websites display RegEx patterns with a '/' character at the beginning and end. You should not enter this character when pasting your RegEx pattern into BestMARC.

Character Classes

Defines the type of character to match.

. Matches any single character
\s Matches any whitespace character
\S Matches any non-whitespace character
\d Matches any digit character (0-9)
\D Matches any character other than a digit
\w Matches any word character: letter, digit, or underscore. Equivalent to [a-zA-Z0-9_]
\W Matches any non-word character: not a letter, digit, or underscore
[abc] Matches any single character between the brackets. Can use dash between chars like a-z, A-Z, or 0-9
[^abc] Matches any single character that is not between the brackets. Can use dash between chars like a-z, A-Z, or 0-9
\ Matches the next character as a literal. Needed to match RegEx characters ^ $ . * + - ? ( ) [ ] { } \ |

Quantifiers

Defines how many times to match the element that preceeds it.

* Matches 0 or more times
+ Matches 1 or more times
? Matches 0 or 1 time
{n} Matches exactly n times
{n,} Matches at least n times
{n,m} Matches between n and m times

Anchors

Matches a position in the string instead of a character.

^ Beginning of string
$ End of string
\b A word boundary
\B A non-word boundary

Groups

Defines a subexpression that allows alternate matches, substitutions, lookaheads, and lookbehinds.

(...) Form a subgroup whose contents can be used in substitutions
(ab|cd) Matches ab or cd. Can use multiple | characters to define additional alternates
(?=...) Positive lookahead: The pattern ahead must match but is not part of the captured match
(?!...) Negative lookahead: The pattern ahead must not match but is not part of the captured match
(?<=...) Positive lookbehind: The pattern behind must match but is not part of the captured match
(?<!...) Negative lookbehind: The pattern behind must not match but is not part of the captured match

Substitutions

Used in the Replace string to replace the match.

$& The whole match
$1 The first match group
$2 The second match group
$n The nth match group
$` The entire text before the match
$' The entire text after the match

Additional Information

Regular Expressions is an advanced topic, with many books and online resources availabile to help you learn how to use them. We recommend that you use an external tool to create and test your RegExes and simply paste them into BestMARC once they are working. There are also sites that collect RegExes and let you search their pattern databases.

There are several different flavors of RegEx, with some varying differences. BestMARC uses the RegEx syntax from Microsoft's .NET if you are using external resources.

The following external resources are not affiliated with BestMARC or Mitinet but may be helpful:


< Previous: Commands Next: Workflows >
Skip Navigation LinksAbout > User Guide > Batch Editing > Global Editing > Regular Expressions
© 2019 Mitinet Library Services ▼