Regular expressions
A regular expression, often shortened to Regex, describes a pattern in text. Use one when a literal search is too specific: for example, to find every product code with the same structure rather than searching for each number separately.
Key points
Use a regular expression when you need a text pattern, such as a family of product codes. Test matching and nonmatching examples first. The effect depends on whether the pattern is used in a filter, replacement, QA rule, tag rule, or segmentation rule.
Searchspeare uses pattern fields in filtering, find and replace, custom QA, custom tags, and segmentation. The same pattern can have very different consequences in those tools, so first decide whether you are finding text, replacing it, flagging a problem, or changing a boundary.
Try a text search before using Regex
If you need every occurrence of “warranty”, use a normal text search. Turn on Regex only when you need pattern behavior.
In Regex mode, some punctuation has a special meaning. Searching for 1.5 can match a character between 1 and 5, because a dot means any character. Searching for 1\.5 asks for the literal decimal point.
Enter a pattern without wrapping it in slashes. Set case sensitivity through the relevant tool's controls.
Learn a few useful building blocks
| Pattern | Meaning | Example match |
|---|---|---|
\d | One digit | 7 |
\d+ | One or more digits | 125 |
\s | A whitespace character | A space or other whitespace |
[A-Z] | One letter in the specified range | P |
[A-Z]{2}\d{4} | Two uppercase letters followed by four digits | AB1234 |
colou?r | The preceding u is optional | color or colour |
cat|dog | Either alternative | cat or dog |
^Note | “Note” at the beginning of the text being checked | A segment starting with that word |
end$ | “end” at the end of the text being checked | A segment ending with that word |
\. | A literal full stop | . |
A quantifier changes how many times the preceding element can occur. + means one or more; * means zero or more; ? means optional; {4} means exactly four. Keep the scope narrow: a pattern such as .* can match much more than you intend.
Try a practical filter
Suppose you need to inspect codes such as AB1234 and CD5678.
- Open the source or target filter settings.
- Enable Regex and case sensitivity if the uppercase form matters.
- Enter
[A-Z]{2}\d{4}. - Inspect the displayed segments and highlighted matches.
- Add more constraints if unrelated text also matches.
This finds the shape of a code. It does not prove the code is valid or present in an external product list.
Use capture groups for replacement
Parentheses capture a part of the match. Numbered references such as $1 and $2 reuse those captured parts in the replacement field.
| Find | Replace | Intended result |
|---|---|---|
(Part)\s+(\d+) | $1 $2 | Keep the label and number while normalizing the gap |
(\d{2})/(\d{2})/(\d{4}) | $3-$2-$1 | Rearrange a date from day/month/year into year-month-day |
The date example only recognizes and rearranges the shape. It does not validate a real calendar date and is unsuitable when the input could be month/day/year. Test assumptions before changing a whole file.
Read the pattern editor's feedback
The editor highlights pattern elements and can report invalid syntax. It can also make normally invisible whitespace easier to see. A pattern that is syntactically valid can still describe the wrong text, so do not stop at “no error”.
Test both a positive example that should match and a negative example that should not. For replacement, inspect the resulting text. For QA, inspect which source/target combinations are flagged. For segmentation, inspect both split and keep-together cases.



Save patterns and ask for help
The Regex library lets you reuse saved patterns through the available library controls. Give a pattern a name that explains its purpose and assumptions.
The Create rule with Searchspeare helper is available inside the pattern-based QA and segmentation rule forms. Describe the behavior and supply examples, then inspect the proposed fields. Accept fills the form; saving and applying the rule are separate steps. See Create rules with Searchspeare for screenshots and complete procedures for both forms.
Troubleshoot unexpected matches
If a pattern matches too much, check dots, optional elements, and repeated groups. If it matches nothing, check case sensitivity, escaping, whitespace, and the side being searched.
Whole-word filtering and Regex are separate modes; Regex controls its own boundaries. A word boundary that is useful for simple Latin text may be unsuitable for another writing system. Test the actual text you are working on.
For ordinary wording changes, return to Find and replace. For reusable quality checks, read QA.