Back reference and forward reference in Regular Expressions
- Back reference is the term used when a capturing group is referenced after we capture it.
- Forward reference is the term for referencing a group before capturing the text using a captured group.
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.