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 |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.