title: Can you help me rewrite my javascript regex using php preg_replace?
body: <p>I have created a javascript regular expression in order to validate comments entered by users in my app. The regex allows letters, numbers some special symbols and a range of emojis</p>
  
  <p>I received help <a href="https://stackoverflow.com/questions/41433382/can-you-help-me-alter-my-regular-expression-to-include-a-particular-range-of-uni/41433719?noredirect=1#comment70100753_41433719">here</a> to correctly format my javascript regular expression and the final expression I am using is as follows:</p>
  
  <h1>Javascript Regex:</h1>
  
  <pre><code>commentRegex =    /^(?:[A-Za-z0-9\u00C0-\u017F\u20AC\u2122\u2150\u00A9 \/.,\-_$!\'&amp;*()="?#+%:;\&lt;\[\]\r\r\n]|(?:\ud83c[\udf00-\udfff])|(?:\ud83d[\udc00-\ude4f\ude80-\udeff]))*$/;
  </code></pre>
  
  <p>I was advised to perform the same validation on the server side (with php) and so I am trying to perform a similar process using preg_replace().</p>
  
  <p>So I would like to replace all characters (that are not contained in the regex), with the empty string. Here is my attempt however it is not working. thanks for any help</p>
  
  <h1>PHP</h1>
  
  <pre><code>$commentText = preg_replace('#^(?:[A-Za-z0-9\u00C0-\u017F\u20AC\u2122\u2150\u00A9 \/.,\-_$!\'&amp;*()="?#+%:;\&lt;\[\]\r\r\n]|(?:\ud83c[\udf00-\udfff])|(?:\ud83d[\udc00-\ude4f\ude80-\udeff]))*$#', '', $commentText);
  </code></pre>
  
  <h1>Edit:</h1>
  
  <p>After taking your advice in the comments I now have the following regex.</p>
  
  <pre><code>$postText = preg_replace('/^(?:[A-Za-z0-9\x{00C0}-\x{017F}\x{20AC}\x{2122}\x{2150}\x{00A9} \/.,\-_$!\'&amp;*()="?\#\+%:;\&lt;\[\]\r\n]|(?:\x{d83c}[\x{df00}-\x{dfff}])|(?:\x{d83d}[\x{dc00}-\x{de4f}\x{de80}-\x{deff}]))*$/', '', $postText);
  </code></pre>
  
  <p>However I am getting a warning </p>
  
  <pre><code>&lt;b&gt;Warning&lt;/b&gt;:  preg_replace(): Compilation failed: character value in \x{} or \o{} is too large at offset 30 in &lt;b&gt;submit_post.php&lt;/b&gt; on line &lt;b&gt;37
  </code></pre>