Raaz
Raaz

Reputation: 1771

Replacing a word with input through regex

I have a string Pigs __(cant)__ fly. I want to replace the word __( )__ with an input field. What is the regex for this? I can do very simple regex stuff but this is going up above my head.

Upvotes: 0

Views: 33

Answers (1)

AkshayM
AkshayM

Reputation: 1441

Try this:

var str = "Pigs __(2cansf33't)__ fly"

var convertedString = str.replace(/\s__\(([a-z0-9']*)\)__\s/, ' '); 

console.log(convertedString)

Let me know if this helps.

Upvotes: 1

Related Questions