What's wrong with my regex?(python)


  • 0
    Z
    class Solution(object):
        def isPalindrome(self, s):
            """
            :type s: str
            :rtype: bool
            """
            # import re
            rule=re.compile(r'[^a-zA-z0-9]')
            result = rule.sub('',s).lower()
            return result[::-1]==result
                
    i use the regex,the online testing system shows:
    Submission Result: Wrong Answer More Details 
    Input:
    "`l;`` 1o1 ??;l`"
    Output:
    false
    Expected:
    true
    when i debug in pycharm,the 'result'='`l``1o1l`'

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.