function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DrawloopSupportDrawloopSupport 

Loop through regex matches

How would one go about looping through all of the matches in a Matcher object? Most of the apex documentation says things like "from the previous match" but I can't even tell how to move between the matches (like previous and next match). Can anyone point me in the right direction, or better yet, post a sample?

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
DrawloopSupportDrawloopSupport

Figured this out:

 

 

Pattern p = Pattern.compile('regex'); Matcher mo = p.matcher('string'); while (mo.find()) { System.debug(mo.group()); }