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


i want capture index of particular regular expression in java string. string may enclosed single quote or double quotes (sometimes no quotes). how can capture index using java?

eg:

capture string -->  class = ('|"|)word('|"|) 

no.

check source code verification

workaround : not standard practice can 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 give index     } 

or

regex r = new regex("yourregex");  // search match within string r.search("your string string");  if(r.didmatch()){ // prints "true" -- r.didmatch() boolean function // tells whether last search successful // in finding pattern. // r.left() returns left string , string before matched pattern  int index = r.left().length(); }  

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -