0

Suppose I have a variable with data in it:

string = "test('Text', '')"

How could I do something like this

string.replace("test('*', '')", "replacedtext")

So I could put a "*" in there and it would replace it if anything was there?

1
  • I wouldn't assign string either, it's a keyword. Commented Mar 9, 2017 at 3:50

3 Answers 3

2

Looks like you want to replace whatever text you may have within the single quotes within the string with "replacedtext". You don't need to use a wild card * for this.

var newstring = string.replace(string.split("'")[1], "replacedtext");

Sign up to request clarification or add additional context in comments.

Comments

0

If it's simply a * then:

string.replace('*', 'replacedText')

Comments

0
result = yourString.replace(/\*/, "your string"); //result is now "your string"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.