0

I am using regular expression in Node.JS

var Regex = require("regex");
var regex = new Regex(/(a|b)*abb/);
regex.test("abb");   // true 
regex.test("cabb");  // false

In this case, the pattern is

`/(a|b)*abb/`

var regex = new Regex(/(a|b)*abb/); is correct

var regex = new Regex('(a|b)*abb'); is error

Now I have a string '(a|b)*abb'. How do I construct a regular expression pattern from this string.

0

1 Answer 1

4

Both are incorrect.

The correct way is to use the RegExp constructor.

var regex = new RegExp('(a|b)*abb');
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.