Matching emojis in C#
<p>I am trying to find a way to filter emojis from utf8 text files. Apparently there is a javascript regex available (<a href="https://raw.githubusercontent.com/mathiasbynens/emoji-regex/master/index.js" rel="nofollow noreferrer">https://raw.githubusercontent.com/mathiasbynens/emoji-regex/master/index.js</a>) which can be used to match emojis. I could not translate this regex to c# dialect (looks like there are some differences i don't understand). Then I tried following simple code to match all non-word and non-space characters in my texts (to go over them manually and select emojis, then put them in a regex and replace them with empty string).</p>

<pre><code>string input = @"some path\";
            List&lt;char&gt; emojis = new List&lt;char&gt;();
            foreach(FileInfo file in new DirectoryInfo(input).GetFiles("*.txt", SearchOption.AllDirectories))
            {
                MatchCollection matches = Regex.Matches(File.ReadAllText(file.FullName), @"[^\w\s]{1}");
                foreach(Match match in matches)
                {
                    string value = match.Value;
                    foreach(char c in value.ToCharArray())
                    {
                        if(!emojis.Contains(c))
                        {
                            emojis.Add(c);
                        }
                    }
                }
            }
            foreach(char c in emojis)
            {
                File.AppendAllText(@"\\Emojis.txt", c.ToString()+"|");
            }
</code></pre>

<p>But I get exception in #develop </p>

<blockquote>
  <p>System.Text.EncoderFallbackException: Unable to translate Unicode
  character \uD83D at index 0 to specified code page.</p>
</blockquote>

<p>Apparently it is not a good idea to convert regex matched characters to characters. Any ideas how can I fix this?
Regards</p>