1

I am getting myArray as null. Can anyone help me?

myRe = new RegExp ("[A-Z]+(\\d+)");
myArray = myRe.exec("book1");
alert(myArray.length);

2 Answers 2

7

Your regular expression is case sensitive; try:

myRe = new RegExp ("[A-Za-z]+(\\d+)");

or:

myRe = new RegExp ("[A-Z]+(\\d+)", "i");
Sign up to request clarification or add additional context in comments.

2 Comments

Or add an i parameter: new RegExp('foo', 'i');
My fault I was using RegexBuddy with Case Insensitive mode turned on. Thank you for the quick answer.
2

It's because you use [A-Z] which is for uppercase.

Use this instead:

pattern = /[a-z](\d+)/i;
myArray = pattern.exec("BOOK1");
alert(myArray.length);

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.