3

I'm struggling to figure out how to exclude my match from the following sample:

myJavascriptArray(["foo","bar"]);

I can match the string no problem with:

myJavascriptArray\(.+\);

Really, all I want is the ["foo","bar"] part.

I can ignore the myJavascriptArray part using:

(?!myJavascriptArray)\(.+\);  // matches (["foo","bar"]);

But then I'm completely lost!

1 Answer 1

3

You can use:

string.match( /myJavascriptArray\((.+?)\)/ )[1];

Or to safeguard:

var m = string.match( /myJavascriptArray\((.+?)\)/ );
var myval = m ? m[1] : "";

This capturing the interested value in a group and use that group in output array.

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

2 Comments

I should have said - I'm not actually going to be using javascript, it will be Ruby but the match looks like it works thank you so much.
Yes similar concept works for ruby or or any other language also.

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.