

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- How to match end of the input using Java RegEx?
- 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?
- Significance of regex match() and regex search() function in 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 start MySQL Server?
- Determining the position and length of the match Java regex
- Removing 0s from start and end - JavaScript
- How not to match a character after repetition in Python Regex?
- How to match at the end of string in python using Regular Expression?
- How can I start writing or editing for Wikipedia?
- Can you allow a regex match in a MySQL Select statement?
- How can I use Python regex to split a string by multiple delimiters?
- How to match the beginning of the input using Java RegEx?
Advertisements