What I have here is a script that changes the value in a textarea via onclick of a button. I do this using Javascript replace together with RegEx. So there's a specified value for every number.
In this sample, however, I couldn't make a letter after a dash to work.
const mapper = new Map();
mapper.set("10th", "11th");
mapper.set("-", "Deleted");
mapper.set("63-51", "40");
mapper.set("121AA", "95");
mapper.set("121-I", "Deleted");
mapper.set("121-OO", "Deleted");
function fixtext() {
const elm = document.getElementById("textarea1");
if (elm) {
elm.value = elm.value
.replace(
/\b\d+(?:[A-Z]|([A-Z])\1|d|th|st|nd)?(|\-\d+)?\b/g,
m => mapper.has(m) ? mapper.get(m) : m
);
}
}
<textarea id="textarea1" rows="4" cols="50">121AA will become 95 and 63-51 will become 40. This should be the same for 121-I and 121-OO.</textarea>
<button class="nbtngreen" onclick="fixtext()">Update</button>
So after a click of the button, 121-I should become Deleted as specified. That's also the case for 121-OO.
I'd appreciate any help on how to fix the RegEx I'm using. Many thanks in advance!
-? Try/\b\d+(?:-?([A-Z])\1?|[rn]d|th|st)?(?:-\d+)?\b|-/i, see the regex demo.\-\d+only matches numbers after-, not letters.-except inside[].