hamed alholi
hamed alholi

Reputation: 69

How to remove specific symbol in text

I'm trying to remove specific text from incoming value

changeable:# this can be changeable
global:# this is global
manager:# this is manager 

what I want:

this can be changeable
this is global
this is manager 

How can I remove it also the space after #

Upvotes: 0

Views: 67

Answers (1)

Code Maniac
Code Maniac

Reputation: 37755

You can use replace method

  • ^ - Start of string
  • [^#]* - Match anything except # zero or more time
  • # - Match #
  • \s* - Match space character zero or more time

let strArr = [`changeable:# this can be changeable`, `global:# this is global`, `manager:# this is manager`]

let textModifier = (str) => {
  console.log(str.replace(/^[^#]*#\s*/, ''))
}

strArr.forEach(textModifier)

Upvotes: 1

Related Questions