- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I match the start and end in Python's regex?
We have the given string ‘TestCountry Hello’. To match and print that part of the string which starts and ends with characters ‘T’ and ‘y’ respectively we use the findall method of module re , word boundary anchor \b and non-whitespace character \S in the regex:
Example
import re result = re.findall(r"\bT\S+y\b", 'TestCountry Hello') print result
Output
to get output as
['TestCountry']
- Related Articles
- How do i match just spaces and newlines with Python regex?
- How to match text at the start or end of a string in Python?
- How to match end of the input using Java RegEx?
- Significance of regex match() and regex search() function in Python
- How can I get a file's permission mask using Python?
- How to Match patterns and strings using the RegEx module in Python
- How to match end of a particular string/line using Java RegEx
- How can I set the 'backend' in matplotlib in Python?
- How to get the certificate's start and expiry date using PowerShell?
- How can I get a file's size in C++?
- How can I set an ImageView's width and height programmatically in Android?
- How do we find the exact positions of each match in Python's regular expression?
- How can I modify an existing column's data type?
- How can I vary a shape's alpha with Tkinter?
- Can 'false' match some string in MySQL?

Advertisements