lundi 12 octobre 2020

Java Matches() returning false? [duplicate]

Why does boolean matches become false? I have used the regex the way I think it should be used and for some reason I still get a false result for matches? I have searched through https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html for information about creating the pattern but still cant figure out why matches is false

import java.util.regex.*; 

public class GFG { 
    public static void main(String[] args) 
    { 
        // create a REGEX String 
        String REGEX = ".*lehigh*"; 

        // create the string 
        // in which you want to search 
        String actualString 
            = "https://www1.lehigh.edu/directory"; 

        // compile the regex to create pattern 
        // using compile() method 
        Pattern pattern = Pattern.compile(REGEX); 

        // get a matcher object from pattern 
        Matcher matcher = pattern.matcher(actualString); 

        // check whether Regex string is 
        // found in actualString or not 
        boolean matches = matcher.matches(); 

        System.out.println("actualString "
                        + "contains REGEX = "
                        + matches); 
    } 
} 

Aucun commentaire:

Enregistrer un commentaire