
- 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
Why do we use re.compile() method in Python regular expression?
The re.compile() method
re.compile(pattern, repl, string):
We can combine a regular expression pattern into pattern objects, which can be used for pattern matching. It also helps to search a pattern again without rewriting it.
Example
import re pattern=re.compile('TP') result=pattern.findall('TP Tutorialspoint TP') print result result2=pattern.findall('TP is most popular tutorials site of India') print result2
Output
['TP', 'TP'] ['TP']
- Related Questions & Answers
- Why do we use question mark literal in Python regular expression?
- How do we use re.finditer() method in Python regular expression?
- How do we use Python Regular Expression named groups?
- Why we should use whole string in Java regular expression
- How do we use Python regular expression to match a date string?
- How to write a case insensitive Python regular expression without re.compile?
- How do we use a delimiter to split string in Python regular expression?
- Why do we use JSON.stringify() method in jQuery?
- Why do we use random.seed() in Python?
- Why do we use pandas in python?
- Why do we use interfaces in Java?
- How to use wildcard in Python regular expression?
- How to use range in Python regular expression?
- How to use variables in Python regular expression?
- Why do we use jQuery over JavaScript?
Advertisements