Position Matching

A position matching pattern is used to match a substring that occurs at a specific location in the text being searched.

SymbolMeaningExample
^Match pattern at start of the string
^ExplainThat! matches
    "ExplainThat!" resources for programmers but not 
    "Search ExplainThat!" or 
    "Only ExplainThat! has the answers"
$Match pattern at end of the string
ExplainThat!$ matches Resources for programmers at 
"ExplainThat!" and "Search ExplainThat!" 
but not "Only ExplainThat! has the answers"
\bMatch any word boundary - i.e. the start or end of a word. Any character that is not alphanumeric or the underscore, _, is treated as a word boundary.
To match "script" in "scripting languages" 
use the pattern \bscript
To match "Javascript" use the pattern script\b   
To match the word "script" in "This script is neat" use the pattern 
\bscript\b
\BMatch any non-word boundary - i.e. pattern within a word.
To match "script" in "inscription" use the pattern 
\Bscript or script\B
Naturally, one can combine patterns to deliver more specific results. For example, ^ExplainThat!$ would match the text string "ExplainThat!" and nothing else.
Regular Expression Sandbox
Model
Data

Do not wrap the model expression in a /.../ pair. The characters ^$.?*!+:=()[]{}|\\ must be escaped - except when then occur inside a character class. Invalid characters will be grayed out.
Result Left Text Match Right Text
       

Download
Jump To...

Colophon