Python Forum
Regex to catch what user has put in text box
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex to catch what user has put in text box
#5
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:

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!
Reply


Messages In This Thread
RE: Regex to catch what user has put in text box - by Pedroski55 - Jun-11-2024, 05:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 1,619 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  try catch not working? korenron 2 1,004 Jan-15-2023, 01:54 PM
Last Post: korenron
  python-docx regex: replace any word in docx text Tmagpy 4 2,478 Jun-18-2022, 09:12 AM
Last Post: Tmagpy
  Multiprocessing queue catch get timeout Pythocodras 1 2,575 Apr-22-2022, 06:01 PM
Last Post: Pythocodras
  twisted: catch return from sql wardancer84 0 1,609 Sep-08-2021, 12:38 PM
Last Post: wardancer84
  how to catch schema error? maiya 0 1,974 Jul-16-2021, 08:37 AM
Last Post: maiya
  is this a good way to catch exceptions? korenron 14 5,084 Jul-05-2021, 06:20 PM
Last Post: hussaind
  pool mysql error - not catch by try\except? korenron 1 2,266 Jul-05-2021, 11:26 AM
Last Post: ibreeden
  Regex text file to store data in list TheSithSiggi 1 1,638 Dec-03-2020, 04:46 PM
Last Post: bowlofred
  try catch question ,get data from main code korenron 7 3,429 Nov-03-2020, 09:28 AM
Last Post: korenron

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020