Can Java String.indexOf() handle a regular expression as a parameter?

No.

Check source code for verification

WorkAround :
Its not standard practice but you can get result using this.

Update:

    CharSequence inputStr = "abcabcab283c";
    String patternStr = "[1-9]{3}";
    Pattern pattern = Pattern.compile(patternStr);
    Matcher matcher = pattern.matcher(inputStr);
    if(matcher.find()){

    System.out.println(matcher.start());//this will give you index
    }

OR

Regex r = new Regex("YOURREGEX");

// search for a match within a string
r.search("YOUR STRING YOUR STRING");

if(r.didMatch()){
// Prints "true" -- r.didMatch() is a boolean function
// that tells us whether the last search was successful
// in finding a pattern.
// r.left() returns left String , string before the matched pattern 
int index = r.left().length();
} 

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)