Javascript (JS) Regular Expression MCQ

This section focuses on the "Javascript Regular Expression" of the Javascript. These Multiple Choice Questions (mcq) should be practiced to improve the Javascript skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. Which among the following regular expression specifies that password should contain at least one capital letter or one digit.

A. /.*[A-Z].*/.test(password) && /.*[0-9].*/.test(password)
B. /.*[A-Z].*/.test(password) || /.*[0-9].*/.test(password)
C. /.*[A-Z][0-9].*/.test(password)
D. None of the above

View Answer


2. Which of the following string will match the RegEx "((d).(dd))$"?

A. 223.123
B. 22.123
C. 223.12
D. 2.2

View Answer


3. Consider the following JavaScript statement containing regular expressions and check if the pattern matches?
var text = "lestfindcourse: 1, 2, 3";
var pattern = /d+/g;

A. text==pattern
B. text.equals(pattern)
C. text.test(pattern)
D. pattern.test(text)

View Answer


4. The regular expression to match any one character not between the brackets is __________

A. [....]
B. [^]
C. [^...]
D. [\D]

View Answer


5.  What would be the result of the following statement in JavaScript using regular expression methods?

A. Returns ["123""456""789"]
B. Returns ["123","456","789"]
C. Returns [1,2,3,4,5,6,7,8,9]
D. Throws an exception

View Answer


6.  What will be the output of the following JavaScript code?
System.out.println( Pattern.matches("[lfc]", "lets") );

A. true
B. false
C. undefined
D. l

View Answer


7.  What will be the output of the following JavaScript code?
System.out.println( Pattern.matches("[lfc]?", "l") );

A. true
B. false
C. undefined
D. l

View Answer


8.  What will be the output of the following JavaScript code?
System.out.println( Pattern.matches("\d", "9") );

A. true
B. false
C. undefined
D. 9

View Answer


9.  What will be the output of the following JavaScript code?
System.out.println( Pattern.matches("[^lfc]", "letsfind") );

A. true
B. false
C. undefined
D. l

View Answer


10.  What will be the output of the following JavaScript code?
System.out.println( Pattern.matches("[lfc]+", "f") );

A. true
B. false
C. undefined
D. 1

View Answer






Also check :


Discussion



* You must be logged in to add comment.