Text Processingflags: gi
Word Boundary (Whole Word Match)
Match the whole word `cat` without matching it inside other words like `concatenate` or `category`.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
\bcat\b (flags: gi)Raw source: \bcat\b
How it works
\b is a zero-width assertion at a word boundary — the position between a word character (\w) and a non-word character (or string edge). Wrapping `cat` in two \b anchors forces the match to start AND end at word boundaries, so `cat` matches but `concat` and `cats` do not.
Examples
Input
The cat sat on the mat.Matches
cat
Input
I will concatenate the strings.No match
—Input
CAT, Cat, cat — all match.Matches
CATCatcat
Common use cases
- •Find-and-replace targeting whole words only
- •Search-engine-style keyword highlighting
- •Linting for forbidden whole-word identifiers
- •Tokenizer fallback in NLP pipelines
Related patterns
Duplicate Word
Text ProcessingDetects consecutive duplicate words using a backreference.
Sentence Boundary
Text ProcessingMatches sentence boundaries (punctuation followed by whitespace and a capital letter).
Hashtag
Text ProcessingMatch hashtags (# followed by word characters) in social media posts, including accented Latin characters.
HCL / Terraform Variable Reference
Text ProcessingMatch Terraform / HCL references like `var.name`, `local.foo`, `module.x.output`, or `data.aws_ami.ubuntu.id`.