Efficient way to search for invalid characters in python

前端 未结 9 1450
萌比男神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条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-07 04:10

    re.match and re.search behave differently. Splitting words is not required to search using regular expressions.

    import re
    symbols_re = re.compile(r"[^<>/\{}[]~`]");
    
    if symbols_re.search(self.cleaned_data('topic_message')):
        //raise Validation error
    

提交回复
热议问题