
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Find Patterns of 10plus1 in a String Using Python Regex
The term "10plus1" is a specific pattern in a binary string that starts with a digit '1' followed by at least one or more '0' and ending with a '1'. In regular expressions this pattern is represented as -
10+ 1
Using re.findall()
The re.findall() method accepts a pattern and a string as parameters, finds the given pattern in the entire string, and returns all the matches in the form of a list.
To find the patterns of "10+1" in a given string, we just need to pass the same as pattern to the findall() method along with the string.
Example
In the following example, we will use the re.findall() function to find that 10plus1 is a string -
import re res = re.findall("10+1", ""10000001 hello world 10011 test100000001test.") print(res)
The output returned by the above code is as follows -
['10000001', '1001', '100000001']
Advertisements