find/match pattern in string


// Java code to illustrate find() method 
  
import java.util.regex.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // Get the regex to be checked 
        String regex = "Geeks"; 
  
        // Create a pattern from regex 
        Pattern pattern 
            = Pattern.compile(regex); 
  
        // Get the String to be matched 
        String stringToBeMatched 
            = "GeeksForGeeks"; 
  
        // Create a matcher for the input String 
        Matcher matcher 
            = pattern 
                  .matcher(stringToBeMatched); 
  
        // Get the subsequence 
        // using find() method 
        System.out.println(matcher.find()); 

你可能感兴趣的:(find/match pattern in string)