Forward references
Back reference is the term used when a capturing group is referenced after we capture it. Likewise, a forward reference is the term for referencing a group before capturing the text using a captured group. In other words, the forward reference refers to a capturing group that appears later in the regular expression pattern. Forward references are only useful if we use them inside a repeated group, since the regex engine will be able to resolve captured groups and populate the forward reference while repeating a match using quantifiers.
As with most modern languages, Java allows us to use the forward reference of the captured group. Forward reference is a fairly complex concept to understand in regex.
Let's consider an example ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access