Can someone help me with this problem of regex? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can someone help me with this problem of regex?

City Social Club issues its membership id in a special format: [LastName initial][FirstName initial][date of birth]-[date of month][gender]- followed by 5 digited number. Eg: Member name: Stephen Marak, Data of birth: 3rd April 1987 gender: Male Member Id :MS03-04M-87256 Here last five digital figures are random number generated. Design a Regex to match the membership id.

16th Apr 2021, 5:52 PM
Ashutosh Raturi
Ashutosh Raturi - avatar
4 Answers
+ 3
import re mname=re.compile(r'Member name:\s?(\w+)\s?(\w+)') date=re.compile(r'Data of birth:\s?(\d+\w+)\s?(\w+)\s?(\d{4})') sex=re.compile(r'gender:\s(Male|Female)') sexual=re.findall (sex,F) birth=re.findall(date,F) name=re.findall(mname,F) print (name ) print(birth ) print(sexual )
16th Apr 2021, 10:47 PM
Amir
Amir - avatar
+ 1
Please post your question just once. Thank you
16th Apr 2021, 5:54 PM
Julian
Julian - avatar
+ 1
Thanks Amir
17th Apr 2021, 4:32 AM
Ashutosh Raturi
Ashutosh Raturi - avatar
0
looks like a homework assignment to me(but not sure) because you can achieve the same result with just simple string operations and no Regex. If suppose this is for the purpose of learning Regex then just learning 2 pages on regex would surely help solve this on your own because this examples are usually being covered on teaching of basic regexs. And also very important "where is your attempt?"
16th Apr 2021, 6:26 PM
Rohit