Efficient way to search for invalid characters in python

前端 未结 9 1433
萌比男神i
萌比男神i 2021-01-07 03:10

I am building a forum application in Django and I want to make sure that users dont enter certain characters in their forum posts. I need an efficient way to scan their whol

9条回答
  •  萌比男神i
    2021-01-07 04:00

    Example: just tailor to your needs.

    ### valid chars: 0-9 , a-z, A-Z only
    import re
    REGEX_FOR_INVALID_CHARS=re.compile( r'[^0-9a-zA-Z]+' )
    list_of_invalid_chars_found=REGEX_FOR_INVALID_CHARS.findall( topic_message )
    

提交回复
热议问题