'Retrieve groups-only from a replace function
I am using named groups in a replacement method, and I want to only work with that groups object, as it may have a variable number of capture groups. As an example:
function reFunc(match, p1, p2, p3, p4, offset, string, groups) {
console.log('*****', groups);
}
"Bob Jones is the mayor of Dallas.".replace(/(?<first>\w+) (?<last>\w+) is the (?<position>\w+) of (?<city>\w+)/, reFunc);
"Bob Jones is the mayor of Dallas, Texas.".replace(/(?<first>\w+) (?<last>\w+) is the (?<position>\w+) of (?<city>\w+), (?<state>\w+)/, reFunc);
Is there a way to just ignore everything except the groups in the replacement function, for example something like:
function reFunc(..., groups) {
...
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
