Check if string is palindrome LeetCode
Disclaimer: Not a Code Reviewer

Your solution looks fine;
Overall, we would want to stay away from regular expressions in solving algorithm problems – especially easy LeetCode questions are to measure our implementation skills;
C# has two simple functions that would do the job of (\W|_):

public class Solution {
    public bool IsPalindrome(string s) {
        var left = 0;
        var right = s.Length - 1;

        while (left &lt; right) {
            if (!char.IsLetterOrDigit(s[left])) {
                ++left;

            } else if (!char.IsLetterOrDigit(s[right])) {
                --right;

            } else {
                if (char.ToLower(s[left]) != char.ToLower(s[right])) {
                    return false;
                }

                ++left;
                --right;
            }
        }

        return true;
    }
}



We can just a bit improve the runtime, but not so much, using a more readable expression such as:

(?i)[^a-z0-9]+;

(?i) matches the remainder of the pattern based on the insensitive flag;


[^A-Za-z0-9]+;




public class Solution {

    public bool IsPalindrome(string s) {

        s = System.Text.RegularExpressions.Regex.Replace(s, @&quot;(?i)[^a-z0-9]+&quot;, &quot;&quot;);

        if (s == null || s == &quot;&quot; || s.Length == 1 || s == &quot; &quot;) {
            return true;
        }

        for (int i = 0, j = s.Length - 1; i &lt;= s.Length / 2  &amp;&amp; j &gt;= s.Length / 2; i++, j--) {
            if (Char.ToLower(s[i]) == Char.ToLower(s[j])) {
                continue;
            }

            return false;
        }

        return true;
    }
}

RegEx Circuit
jex.im visualizes regular expressions:


Demo
If you wish to simplify/update/explore the expression, it's been explained on the top right panel of regex101.com. You can watch the matching steps or modify them in this debugger link, if you'd be interested. The debugger demonstrates that how a RegEx engine might step by step consume some sample input strings and would perform the matching process.

Happy Coding! ( •ˆ_ˆ• )