- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Explain subn() methods of “re” module in Python ?
A regular expression is a special sequence of characters that helps you match or find other strings or sets of strings, using a specialized syntax held in a pattern. Regular expressions are widely used in UNIX world. The re module in python refers to the module Regular Expressions (RE). It specifies a set of strings or patterns that matches it. Metacharacters are used to understand the analogy of RE.
subn()method is similar to sub() and also returns the new string along with the no. of replacements.
Syntax
re.subn (pattern, repl, string, count=0, flags=0)
Example
import re print(re.subn('ov', '~*' , 'movie tickets booking in online')) t = re.subn('ov', '~*' , 'movie tickets booking in online', flags = re.IGNORECASE) print(t) print(len(t)) print(t[0])
Here you can see that, subn() method It returns a tuple with count of total of all the replacements as well as the new string.
Output
('m~*ie tickets booking in online', 1) ('m~*ie tickets booking in online', 1) 2 m~*ie tickets booking in online
- Related Articles
- Explain calendar module in python?
- Can we re-throw errors in JavaScript? Explain.
- Explain the Java regular expression construct "re?".
- Explain the Sub-Expression "(?> re)" in Java Regular Expressions
- Briefly explain the various methods of irrigation involved in agriculture? Explain each of these methods in detail.
- Fraction module in Python
- colorsys module in Python
- Keyboard module in Python
- Import module in Python
- struct module in Python
- Pygorithm module in Python
- Explain irrigation methods
- Explain Class Methods in Coffeescript
- Python getpass Module
- The time Module in Python

Advertisements