Example 1 — Escape Money Text for a Pattern
Turn a price string into a safe literal piece of a regex.
<?php
$literal = preg_quote('price $5.00', '/');
echo $literal, PHP_EOL;
$pattern = '/' . $literal . '/';
echo preg_match($pattern, 'The price $5.00 is OK'), PHP_EOL; How It Works
- The raw text contains $ and . , which are special in regex.
- preg_quote() escapes them so they mean “dollar” and “dot”.
- The escaped text is wrapped in / delimiters to build a full pattern.
- preg_match() finds the exact phrase in the sentence and returns 1.

