java - Find some text in a string on matching to a reg-ex -


i looking sentences of form. "....x educated @ y..." in third field of each line of document of text. x known , y unknown. on successful match, how can value of y? following code:

    pattern p1 = pattern.compile(".* educated @ .*");     int count = 0;      while((line = br.readline()) != null){         string datavalue[] = line.split("\t");         string text = datavalue[2];         matcher m = p1.matcher(text);         if(m.matches()){             count++;             //system.out.println(text);             //how y?          }     } 

i'm new reg-ex. appreciated.

capture found text group:

pattern p1 = pattern.compile(".* educated @ (.*)");//note parenthesis int count = 0;  while((line = br.readline()) != null){     string datavalue[] = line.split("\t");     string text = datavalue[2];     matcher m = p1.matcher(text);     if(m.matches()){         count++;         system.out.println(m.group(1));      } } 

please see https://docs.oracle.com/javase/tutorial/essential/regex/groups.html more information


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -