Python Online Compiler & Playground
HTML/CSS/JavaScript
HTML
CSS
Javascript
C++
C
PHP
Java
Python
Swift
C#
Ruby
Node.JS
Kotlin
jQuery
Go
R
TypeScript
Start Python Course
Register
Verify if first and last words are equal
+2
Author: Cristian Baeza Jimenez
Dark
Public
Save
PY
py
1
2
3
4
5
6
7
8
9
10
import
re
pattern = r
"(\w+)\s+(\w+\s*\w+)+\s+(?=\1)"
#
Text1=
"azqr efg ddd faaa hdj hgg dd dhd ddd hdhs azqr"
# put here the text
if
re.match
(
pattern
,
Text1
):
print
(
"Match"
)
else
:
print
(
"No match"
)
Enter to Rename, Shift+Enter to Preview
OUTPUT