0

I have this string something='http://example.com/something' and how can I replace the something=' with nothing?

when I do str.replace('something='','') I got syntax error. I tried str.replace('something=\'','') and expect to escape the single quote with slash, it doesn't work too.

3 Answers 3

3

str.replace('something='','') will of course lead to a syntax error.

Try

str.replace("something='","")

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

Comments

2

I believe what you are looking for is a replacement of something=' and all ticks (') including the closing one... So you could use this:

var str = "something='http://example.com/something'";

alert(str.replace(/something='(.*)'/, "$1"));

Comments

1

You need to update the str variable with the returned value since String#replace method doesn't update the variable.

str = str.replace('something=\'', '')

Although it's better to use double quotes instead of escaping.

str = str.replace("something='", '')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.