Copy link to clipboard
Copied
I know this code
.replace(/-/g, '');
Delete only one letter of a word or text
But 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:
MY TEXT
However, there would be some conse
...Copy link to clipboard
Copied
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:
MY TEXT
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.
Copy link to clipboard
Copied
Thank you for your continued cooperation with me
You are doing a great favor with everyone
With all my heart I thank you very much and wish you success always