regular expression with special chars
Question: I need a regular expression to validate string with one or more of these
characters:

  * a-z 
  * A-Z 
  * ' 
  * àòèéùì
  * simple white space

FOR EXAMPLE these string are valide:

    
    
    D' argon calabrò
    
    maryòn l' Ancol
    

these string are NOT valide:

    
    
    hello38239
    
    my_house 
    
    work [tab] with me
    

I tryed this:

re.match(r"^[a-zA-Z 'òàèéìù]+$", string )

It seems to work in my python shell but in Django I get this error:

    
    
    SyntaxError at /home/
    
    ("Non-ASCII character '\\xc3' ...
    

Why ?

* * *

Edit:

I have added # -_\- coding: utf-8 -_ \- at the top of my forms.py but the
strings with à,è,ò,ù,é or ì doesn't match never.

This is my forms.py clean method:

    
    
        def clean_title(self):
    
            if(re.match(r"^[a-zA-Z 'òàèéìù]+$", self.cleaned_data['title'].strip())):
                return self.cleaned_data['title'].strip()               
            raise forms.ValidationError(_("This title is not valid."))
    


Answer: If you user Non-ASCII characters in your python source files you should add
proper encoding to the top of your source file like this:

    
    
    # -*- coding: utf-8 -*-
    utf_string='čćžđšp'
    

[Defining Python Source Code
Encodings](http://www.python.org/dev/peps/pep-0263/)

This seems to work fine for me:

    
    
    >>> import re
    >>> mystring = "D' argon calabrò"
    >>> matched = re.match(r"^([a-zA-Z 'òàèéìù]+)$", mystring)
    >>> print matched.groups()
    ("D' argon calabr\xc3\xb2",)
    

