Copy link to clipboard
I know this code.replace(/-/g, '');Delete only one letter of a word or textBut there are some words that contain more than one symbol or strange character such as ( ! @ # $ % ^ & * )
I just want to modify the code to delete any letter or group of letters inside the word
That appears to be a literal hyphen character, not a "metacharacter".
To delete anything that is not an upper/lowercase alphabetical letter, number, hyphen, underscore or space:
.replace(/[^A-Za-z0-9-_ ]/g, '');
Basically, whatever literal character inside the [^] is retained. You are specifying what to keep, with everything not explicitly set removed.
The input string of:
MY TEXT! @ # $ % ^ & *
Would result in:
However, there would be some conse
However, there would be some consecutive garbage word spaces left at the end, therefore, a second regex cleanup would be required:
.replace(/ +$/g, '');
That being said, regex is very much case-dependent, so generic replies as above may or may not be 100% successful without real examples.
Thank you for your continued cooperation with meYou are doing a great favor with everyoneWith all my heart I thank you very much and wish you success always