Java Regex cant save text to string -
i trying save bolded text string.
have come regex "routename?.+?routelengthkm" , according online regex tester should me want find method returning true/false. how can save bolded text string?
"routes:[{routename:dulles toll rd w; sr-28 s,routedurationinminutes:18,routelengthkm:21.474,routelengthmiles:13.343320854,toll:true},{routename:frying pan rd; sr-28 s,routedurationinminutes:18,routelengthkm:19.437,routelengthmiles:12.077588127,toll:false}
package regex; import java.util.regex.*; public class regexclass { public static void main (string args[]){ pattern p= pattern.compile("routename?.+?routelengthkm"); matcher m= p.matcher("routes:[{routename:dulles toll rd w; sr-28 s,routedurationinminutes:18,routelengthkm:21.474,routelengthmiles:13.343320854,toll:true},{routename:frying pan rd; sr-28 s,routedurationinminutes:18,routelengthkm:19.437,routelengthmiles:12.077588127,toll:false}]"); system.out.println(m.find()); } }
m.find();
launch matching engine. try match regex against text. returns true
if match found, , false
if no match found. normally, use construct find matches:
while(m.find()) {}
after having found match (i.e. after m.find();
or better if (m.find()) {
), can retrieve match m.group(n);
n
group number. 0 full match group , other numbers there (1,2,3,...) refer subgroups (things in parentheses).
Comments
Post a Comment