Bulk Replace
Reference

Wildcards vs Regular Expressions in Find and Replace: Which Should You Use?

Wildcards or regex for your find and replace? See how * and ? differ between the two, side-by-side examples, and when plain text is the safest choice.

Updated 5 minute read The Bulk Replace team

Use wildcards when you only need "any characters here" or "any one character here": they are short, easy to read and hard to get badly wrong. Use regular expressions when you need precision: digits only, whole words, optional parts, repeats, alternatives, or capture groups to rearrange text in the replacement. And use plain text whenever the text you are replacing is fixed, because it has no special characters at all. The trap is that * and ? mean different things in each: in wildcards, * is "any run of characters", while in regex it is "zero or more of the previous item", so the wildcard * is written .* in regex.

Below is a side-by-side comparison, a translation table, and guidance on which mode to pick for common jobs.

The three modes compared

Plain textWildcardsRegex
Special charactersNoneTypically * and ?Many: . * + ? ( ) [ ] { } ^ $ | \
Learning curveNoneMinutesHours to learn, years to master
Can say "digits only"NoNo (in most tools)Yes: \d+
Whole wordsWith a whole-word optionWith a whole-word optionYes: \b
Optional parts or alternativesNoNoYes: ?, |
Reuse matched text in the replacementNoRarelyYes: $1
Risk of matching too muchLowMediumDepends on the pattern

Same symbols, different meanings

The biggest source of confusion is that both systems use * and ?:

SymbolIn wildcardsIn regex
*Any run of characters, including noneZero or more of the item before it
?Exactly one characterThe item before it is optional; or, after a quantifier, makes it lazy
.A literal dotAny character
[abc]One of a, b or c (in many tools)One of a, b or c

Take file?.txt. As a wildcard, it matches file1.txt and fileA.txt: "file", any one character, ".txt". As a regex, it means "fil", an optional "e", then any character, then "txt", so it matches file.txt and fil-txt but not file1.txt. Same text, very different results. If a pattern behaves strangely, the first thing to check is which mode is switched on.

Translating wildcards to regex

WildcardRegex equivalentBetter regex, if you know more
*.txt.*\.txt[^\\/]*\.txt$ for a file name only
Chapter *Chapter .*Chapter \d+ if it is always a number
IMG_????.jpgIMG_....\.jpgIMG_\d{4}\.jpg
v?.?v.\..v\d\.\d
*error*.*error.*\berror\b (no need for the stars in a search)

The pattern is mechanical: every wildcard * becomes .*, every ? becomes ., and every literal dot or other regex symbol gets a backslash. The third column shows why people switch to regex: once you know the variable part is digits, you can say so, and the pattern stops matching things it should not. The regex cheat sheet lists the building blocks.

Word's wildcards are their own system

Microsoft Word has a Use wildcards option in its Find and Replace dialog (under More >>). It looks like regex in places, but it is a separate syntax:

  • ? is one character and * is any string, like other wildcards.
  • @ means one or more of the previous character or expression, where regex would use +.
  • < and > mark the start and end of a word, where regex uses \b.
  • [!a-z] means "not a lowercase letter", where regex uses [^a-z].
  • {2,4} sets a repeat count, and parentheses with \1 in the Replace box reuse a group, much like regex.

Patterns copied from a regex guide usually fail in Word, and the reverse is also true. Word's wildcards also only work inside Word documents; for plain-text files, use a text tool.

Wildcards are still everywhere in file filters

Even when you search the contents with regex, you almost always pick the files with wildcards. *.html *.css in Notepad++, -Include *.html,*.css in PowerShell and *.{html,css} in VS Code are all wildcard or glob patterns, not regex. Writing .*\.html in a file filter box will usually match nothing. See limiting find and replace to specific file types for each tool's filter syntax.

Wildcard pitfalls

Wildcards are simpler, but they are not risk-free:

  • The star can reach further than you think. In many tools, * matches as much as it can, much like a greedy .* in regex. Copyright * Acme on a line that mentions Acme twice may run on to the second one. Keep the fixed text on both sides of the star as specific as you can, and look at where each match ends.
  • Literal stars and question marks. To find a real * or ?, the escape rules differ by tool. Word uses a backslash; other tools may need you to switch to plain text for that rule.
  • No "not". Most wildcard systems cannot say "anything except a quote" or "only if not followed by". When you need that, it is time for regex.

Which mode for which job?

JobModeWhy
Rename a product or fix a typoPlain text, whole wordThe text is fixed
Change a URL with a query stringPlain textAvoids escaping ? and .
Remove a comment line whose middle variesWildcards or regexOnly "anything here" is needed
Change a version number, whatever it isRegexNeeds "digits and dots only"
Reorder dates or namesRegexNeeds capture groups
Match one exact IP addressRegexNeeds guards so longer addresses do not match
Remove blank or trailing-space linesRegexNeeds line anchors and whitespace classes

A simple test: if you can describe the variable part only as "anything", wildcards are enough. If you find yourself saying "a number", "a word", "either this or that" or "the same thing again", you need regex. For a first step into regex in a replacement, see capture groups in find and replace.

Mixing modes in one job

Large jobs often need all three: plain text for a brand name, a wildcard rule for a comment that varies, and a regex rule for dates. Bulk Replace sets the mode per rule (plain text, wildcards or full regex, each with case-sensitive and whole-word options), and runs a stack of rules in order during one pass. Exact wildcard rules vary between tools, so check a wildcard rule in the before/after preview before you apply it, the same as you would a regex. Bulk Replace backs up every run, so a rule that matched more than expected can be undone in one click.

Frequently asked questions

Does * mean the same thing in wildcards and regex?

No. In wildcards * means any run of characters. In regex * means zero or more of the previous item, so the wildcard * is written .* in regex.

When should I use plain text instead?

Use plain text when you are replacing an exact word or phrase. It is the simplest option and has no special characters to escape.

Are Word wildcards the same as regex?

No. Word's Use wildcards option has its own syntax, such as @ for one or more of the previous character and < > for word starts and ends.

Get three guides like this every month, plus software update notices.Subscribe →