0
var re = "^abc";

How to create a RegEx from this variable to be able to test some strings with it like this:

/THE_re_VARIABLE_HERE/i.test( someString );

2 Answers 2

1

You'll have to use the class constructor:

var re = "^abc";
new RegExp( re, 'i' ).test( someString );
Sign up to request clarification or add additional context in comments.

Comments

1

You can use RegExp method:

var re = "^abc";
new RegExp(re,'i').test( someString );

See more about RegExp here

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.