I'm trying to target a dash or hyphen using RegEx. This seems to be impossible with how I'm using it though. The other answers I found online doesn't seem to match my scenario.
Scenario:
What should happen is if I click a button, this script will replace the specified numbers + letters. It's working fine, until now when I'm about to include a hyphen in the list.
Please take a look at the RegEx used below and here's the code:
const mapper = new Map();
mapper.set("10th", "11th");
mapper.set("-", "Deleted");
mapper.set("63", "Deleted");
mapper.set("63-5", "Deleted");
mapper.set("121AA", "95");
function fixtext() {
const elm = document.getElementById("textarea1");
if (elm) {
elm.value = elm.value
.replace(
/\b\d+(?:A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|AA|BB|CC|DD|EE|FF|GG|HH|II|JJ|KK|LL|MM|NN|OO|PP|QQ|RR|SS|TT|UU|VV|WW|XX|YY|ZZ|d|th|st|nd)?\b/g,
m => mapper.has(m) ? mapper.get(m) : m
);
}
}
<textarea id="textarea1" rows="4" cols="50">(10th ed), Pretrial Proceedings sample 121AA and - and 63 63-5</textarea>
<button class="nbtngreen" onclick="fixtext()">Update</button>
For 63-5, it should be changed as a whole and not as Deleted-5
I tried using several RegEx I saw online to escape hyphen or to match it. Here's some of them:
[]-]
[a-zA-Z0-9!$* \t\r\n\-]
[-]
[abc-]
None of these works for me or I cannot understand how to make it work this time.
I also would really like to shorten my RegEx but this is the problem as well. [A-z] or something like this doesn't work as well.
I'd really appreciate any help on how to fix this. Thanks in advance!