In this section, we are going to find the successively repeated character using Regular Expression.
In this section, we are going to find the successively repeated character using Regular Expression.In this section, we are going to find the successively repeated character using Regular Expression. For this, we have specified a word 'programming' and with use of Pattern and Matcher class, we have found that 'm' is repeated successively.
Here is the code of Main_Class.java
import java.util.regex.*; public class Main_Class{ public static void main(String[] args){ String st = "programming"; Pattern p = Pattern.compile("(\\w)\\1+"); Matcher m = p.matcher(st); if (m.find()){ System.out.println("Repeated character is " + m.group(1)); } } } |
Output:
Repeated Character is m |