Search processing.org:

Reference for Processing version 1.0.1+. If you have a previous version, use the reference included with your software. If you see any errors or have any comments, let us know.

Name

### matchAll()

Examples

    String s = "Inside tags, you will find <tag>multiple</tag>
                <tag>pieces</tag> of <tag>content</tag>.";

    String[][] m = matchAll(s, "<tag>(.*?)</tag>");
    for (int i = 0; i < m.length; i++) {
      println("Found " + m[i][1] + " inside a tag.");
    }
    // Prints "Found multiple inside a tag. Found pieces inside a tag. Found
    // content inside a tag." to the console

Description

The matchAll() function is used to apply a regular expression to a piece of text, and return a list of matching groups (elements found inside parentheses) as a two-dimensional String array. No matches will return null. If no groups are specified in the regexp, but the sequence matches, a two dimensional array is still returned, but the second dimension is only of length one.
To use the function, first check to see if the result is null. If the result is null, then the sequence did not match at all. If the sequence did match, a 2D array is returned. If there are groups (specified by sets of parentheses) in the regexp, then the contents of each will be returned in the array. Assuming, a loop with counter variable i, element [i][0] of a regexp match returns the entire matching string, and the match groups start at element [i][1] (the first group is [i][1], the second [i][2], and so on).
The syntax can be found in the reference for Java's Pattern class. For regular expression syntax, read the Java Tutorial on the topic.

Syntax

    matchAll(str, regexp)

Parameters

str | the String to search inside
regexp | the regexp to be used for matching

Returns | String[][]
Usage | Web & Application
Related | match() split() splitTokens() join() trim()

Updated on November 22, 2008 08:39:25pm PST