If you change the replacement empty string to '$', the difference becomes much clearer: See more linked questions. Default is True. Checking both typeof and instanceof feels like good advice if your code may be called by others'. The character class is the most basic regex concept after a literal match. PJ Brunet. @Mallow your example would be great for validation, but not sanitizing. It'll take a single string argument and escape all regex characters, making the result safe to pass to new RegExp().. The replace method returns a new string after the replacement. Examples Return Value: Returns a string or an array with the replaced values: PHP Version: 4+ Changelog: The count parameter was added in PHP 5.0 Before PHP 4.3.3, this function experienced trouble when using arrays as both find and replace parameters, which caused empty find indexes to be skipped without advancing the internal pointer on the replace array. Any business logic at client side is written in JavaScript and used in HTML pages in