Jun-11-2024, 05:08 PM
(This post was last modified: Jun-12-2024, 05:33 AM by Pedroski55.)
I think you need to know a bit about what to anticipate when creating a re expression.
At first you said Firstname.Lastname and I presumed you meant English.
Your thing here is: something followed by . maybe repeated but not . at the end.
\S will find anything, including the hyphens used in some names, like Henry James William Forsythe-Wallington-Beardsley-Carruthers
\S stops at space, \S is the opposite of \s
If someone enters any of these as names:
But if monsieur enters:
At first you said Firstname.Lastname and I presumed you meant English.
Your thing here is: something followed by . maybe repeated but not . at the end.
\S will find anything, including the hyphens used in some names, like Henry James William Forsythe-Wallington-Beardsley-Carruthers
\S stops at space, \S is the opposite of \s
If someone enters any of these as names:
name = '王聪明 的 弟弟 Pedro Rodriguez Carlos.Sanchez.Rumores.Paz.Pasamar' name2 = '王聪明 的 弟弟 Pedro Rodriguez Carlos.Sanchez-Rumores-Paz.Pasamar' name3 = '王聪明 的 弟弟 Pedro Rodriguez Carlos.Sanchez-Rumores-Paz.Pasa-mar'You can find the bits connected with . using:
e = re.compile(r'(\S+\.)+\S+')
Output:res = i.search(name3)
res.group()
'Carlos.Sanchez-Rumores-Paz.Pasa-mar'
res = i.search(name)
res.group()
'Carlos.Sanchez.Rumores.Paz.Pasamar'
res = i.search(name2)
res.group()
'Carlos.Sanchez-Rumores-Paz.Pasamar'
But if the user is French and enters:nombre = "Pierre le Guen le Mercier"You won't get anything!
But if monsieur enters:
nombre2 = "Pierre.le.Guen.le.Mercier" res = i.search(nombre2)
Output:res.group()
'Pierre.le.Guen.le.Mercier'
Regex expressions are a science unto themselves!