0

Regular expression

I want the regular expression that checks if the first and last words of a given string are same or not? Please answer as soon as possible!

11th Feb 2018, 11:34 AM
Sri Harsha
Sri Harsha - avatar
4 Respuestas
+ 1
here the code to check that with rwgular expression:https://code.sololearn.com/cs97nAm7wLWr/?ref=app
4th Jul 2018, 10:44 PM
Cristian Baeza Jimenez
Cristian Baeza Jimenez - avatar
+ 6
RegEx are best suited for finding *patterns* not really efficient in your task, at least as you described it. You might want to consider another approach: s = "Been there, where you've been" temp = s.lower().split() print(temp[0] == temp[-1]) # first equals to last
11th Feb 2018, 4:54 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
Checking weather an email address is real
24th May 2022, 6:46 AM
Sai Manikanta
0
This regex can get the text if the first and last words are equal: (\w+)(\s\w+)+\s?(?=\1)\1
18th Jun 2018, 9:20 AM
Cristian Baeza Jimenez
Cristian Baeza Jimenez - avatar