# `preg_quote()` and the `#` Character

> Section in “New and Extended Functionality › Regular Expressions” of the book [PHP 7 Explained](https://php7explained.com/) by Sebastian Bergmann and Stefan Priebsch, published by thePHP.cc. The book covers PHP 7.0 to 7.4 and was last updated in November 2020. HTML version: <https://php7explained.com/new-and-extended-functionality/regular-expressions/preg_quote-and-the-character/>

The `preg_quote()` function is used to prefix every character of a string that is part of the regular expression syntax with a `\` character. Prior to PHP 7.3, the `#` character was not prefixed with a `\` character.

``` php
var_dump(preg_quote('.\+*?[^]$(){}=!<>|:-#'));
```

Executing the code shown above with PHP 7.3 and newer will print the output shown below:

    string(42) "\.\\\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:\-\#"

Executing the code shown above with PHP 7.2 and older printed the output shown below:

    string(42) "\.\\\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:\-#"

---

Previous: [PCRE 2](https://php7explained.com/new-and-extended-functionality/regular-expressions/pcre-2/index.html.md) | Next: [preg_replace_callback_array()](https://php7explained.com/new-and-extended-functionality/regular-expressions/preg_replace_callback_array/index.html.md)
