English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Subexpression/Meta-character " (?> re) "Match independent patterns without backtracking."
import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class PatternExample { public static void main(String args[]) { //Read a string from the user System.out.println("Enter a String"); Scanner sc = new Scanner(System.in); String input = sc.next(); String regex = "(?>[0-9])"; //Compile the regular expression Pattern pattern = Pattern.compile(regex); //Retrieve the matcher object Matcher matcher = pattern.matcher(input); //Verify whether a match occurs boolean bool = matcher.find(); if(bool) { System.out.print("Match found"); } else { System.out.print("Match not found"); } } }
Output result
Enter a String 9848022338 Match found