Flags
In addition to the flags supported by Java, RegExPlus adds some additional ones that make it easy to use a regular expression written in a different syntax.
Duplicate names
Flag: DUPLICATE_NAMES
By default, capture group names must be unique. If multiple groups with the same name exist, a PatternSyntaxException is thrown.
By setting this flag, multiple capture groups with the same name are allowed.
Allowing duplicate names can also be enabled via the embedded flag
expression (?J)
.
Verify groups
Flag: VERIFY_GROUPS
When compiling a pattern, verifies that all referenced groups exist.
If this flag is set, a PatternSyntaxException will be thrown if the pattern contains a reference to a non-existent group, whereas, by default, no exception would be thrown.
Perl octal
Flag: PERL_OCTAL
Use Perl's octal syntax (instead of Java's).
That is, \n
is a back reference if at least that
many groups have occurred at the current point in the pattern. Otherwise, up to
the first three (octal) digits are used to form an octal code, and any
additional trailing digits will be treated literally.
.NET numbering
Flag: DOTNET_NUMBERING
Use .NET numbering for capture groups (instead of Java's).
In .NET, named-capture groups are numbered like unnamed groups, but numbering of named groups starts after all unnamed groups have been counted.
For example, the expression ((?<One>A)B)?(?<Two>C)(D)
produces the following
capturing groups by number and name.
Num | Name | Pattern |
---|---|---|
0 | none | ((?<One>A)B)?(?<Two>C)(D) |
1 | none | ((?<One>A)B) |
2 | none | (D) |
3 | One | (?<One>A) |
4 | Two | (?<Two>C) |
Explicit capture
Flag: EXPLICIT_CAPTURE
Enables explicit capture mode.
In this mode, unnamed capture groups don't capture - that is, they are treated like non-capture groups. However, named capture groups can still be used for capturing (and they acquire numbers in the usual way).
Explicit capture mode can also be enabled via the embedded flag expression
(?n)
.
Note: this feature is taken from .NET.