• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Delete more than one strange letter from the word

Enthusiast ,
Sep 19, 2022 Sep 19, 2022

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

TOPICS
Actions and scripting , SDK

Views

103

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 19, 2022 Sep 19, 2022

@Mohamed Hameed 

 

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

...

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 19, 2022 Sep 19, 2022

Copy link to clipboard

Copied

@Mohamed Hameed 

 

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 19, 2022 Sep 19, 2022

Copy link to clipboard

Copied

LATEST

@Stephen_A_Marsh 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines