0

I'm trying to get the content between apostrophes but I messed up something most likely because I only get null.

string.match(/_\('*'\)/)

I need to get OK from this "_('OK')"

4

1 Answer 1

1

You did not use a (sub)pattern to match any chars but ' zero/one or more times + you need to capture the contents in between single quotes to later access the Group 1 contents after getting the match with String#match:

var s = "_('OK')";
var res = s.match(/_\('([^']*)'\)/);
if (res) {
  console.log(res[1]);  
}

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

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.