VOOZH about

URL: https://www.geeksforgeeks.org/dsa/find-all-the-patterns-of-101-in-a-given-string-using-regular-expression/

⇱ Find all the patterns of "1(0+)1" in a given string using Regular Expression - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Find all the patterns of "1(0+)1" in a given string using Regular Expression

Last Updated : 23 Jul, 2025

In Set 1, we have discussed general approach for counting the patterns of the form 1(0+)1 where (0+) represents any non-empty consecutive sequence of 0’s.In this post, we will discuss regular expression approach to count the same. Examples:

Input : 1101001
Output : 2

Input : 100001abc101
Output : 2

Below is one of the regular expression for above pattern

10+1

Hence, whenever we found a match, we increase counter for counting the pattern.As last character of a match will always '1', we have to again start searching from that index. 

Implementation:


Output
2

Time Complexity: O(n) 
Auxiliary Space: O(1)

Related Articles :

Comment