Sorry if this has been answered already. I tried to look for it but maybe I can't figure out how to word my question properly.
Making a little HTML app with a simple regular expression replacement processor. User can input: text, regex pattern, replacement pattern. Running into a snag if more than 9 groups are used though and the user wants to place a number beside the group.
Example:
- Text:
ABCDEFGHIJ... - Pattern:
(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(10 groups) - Replacement:
$10
This would return J, but what if the user wants to return A0? How can we replace with $1 0 without a space in between?
The gist of my code is thus:
let input = document.querySelector('#input').value
let regex = eval(document.querySelector('#pattern').value)
let replacement = document.querySelector('#replacement').value
document.querySelector('#output').value = input.replace(regex, replacement)
I'm doing a little more error checking and processing than that, but you get the point.
