Accent character problem

S

Sallu

Hi all and one
i wrote this script, working fine without fail( just run it)

import re
value='This is Praveen'
print value
#value = 'riché gerry'
#words=str(value.split()).strip('[]').replace(', ', '') ( here i tried
to convert in to list and then back to string)
#print words
richre=re.compile(r'[a-zA-Z0-9]')

if(richre.match(value)):
print "Valid"
else:
print "Not allowed special characters"

Output 1: (Fair)
This is Praveen
Valid
but when i change the value like
value='éhis is Praveen'
then

Output 2:(Fair)
éhis is Praveen
Not allowed special characters
(because i wanted to check out the ascent(é) character so its working
fine no issue)

but when i give ascent(é) character in middle like
value='This és Praveen'

Output 3:(not fair)

This és Praveen
Valid
even it have ascent character it should display message "Not allowed
special characters"
Please help me out.
Thanks
 
D

Diez B. Roggisch

Sallu said:
Hi all and one
i wrote this script, working fine without fail( just run it)

import re
value='This is Praveen'
print value
#value = 'riché gerry'
#words=str(value.split()).strip('[]').replace(', ', '') ( here i tried
to convert in to list and then back to string)
#print words
richre=re.compile(r'[a-zA-Z0-9]')

if(richre.match(value)):
print "Valid"
else:
print "Not allowed special characters"

Output 1: (Fair)
This is Praveen
Valid
but when i change the value like
value='éhis is Praveen'
then

Output 2:(Fair)
éhis is Praveen
Not allowed special characters
(because i wanted to check out the ascent(é) character so its working
fine no issue)

but when i give ascent(é) character in middle like
value='This és Praveen'

Output 3:(not fair)

This és Praveen
Valid
even it have ascent character it should display message "Not allowed
special characters"
Please help me out.

You only test the *first* character. You need to modify your rex using a
+, like this:

richre=re.compile(r'[a-zA-Z0-9]+')

Only then it will match the whole word.

Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top