Find all matches of a regex in Java -



Find all matches of a regex in Java -

i'm using regex functionality in java. can first match correctly. how matches? can utilize m.find(int start), there way using 1 call?

string pattern="span\\(trace_id:(\\d+), name:(\\w+), id:(\\d+), parent_id:(\\d+)"; pattern r = pattern.compile(pattern); matcher m = r.matcher(line); if (m.find()) { system.out.println("found value: " + m.group(0) ); (int count = 1; count <= m.groupcount(); count ++) { system.out.println("found value: " + m.group(count) ); } }

in order find matches given pattern in given input, iterate on boolean find() method of matcher, such:

while (m.find()) { ...

edit after question edit: there no single method match all. there method replace matches of pattern in given string (e.g. string.replaceall) uncertainty want here.

java regex

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -