go to previous page   go to home page   go to next page

Answer:

The DOS/Windows style CRLF ends of lines might be changed to Unix style LF ends of lines.

Decent text editors give you control over this, but you need to know that it might happen.


Capture Groups

Regular Expression
String
Group 0
Group 1 Group 2 Group 3 Group 4

A capture group in an RE is a sub-expression surrounded by parentheses. Here is a RE containing a capture group:

[a-z]+([0-9]+)[a-z]+

If the RE matches a substring, then that substring is Group 0.

The part of the substring that matches the first capture group is "captured" (stored in an object) and may be used later. That part is Group 1.

Java programs may access the data in a capture group after the matching has been done. This is explained further in the chapters on class String and class Pattern.

Play with the applet. Change what part of the expression is surrounded by parentheses to change what part of the string is captured. You can put in additional sets of parentheses to form additional capture groups.

Details: The parentheses must surround a legal subexpression. It is OK if they surround the entire expression, this just means that the entire match will be group 1 (in addition to being group 0).

If a quantifier is placed to the right of a capture group, as in ([0-9])+ then the last substring matched by the group will be captured. (This will be the last digit matched, in this example.)


QUESTION 10:

Is this expression   [a-z]+([0-9]+[a-z])+  legitimate?