Classes And Modules - Study Mode

[#1] The regular expression to match any one character not between the brackets is
Correct Answer

(C) [^…]

Explanation

Solution: The [^…] character class is used to match or draw any one character not between the brackets.

[#2] What does /[^(]* regular expression indicate ?
Correct Answer

(C) Match zero or more characters that are not open paranthesis

Explanation

Solution: We should always be careful while using * and ? as repetition characters as they may match zero instances of whatever precedes them, they are allowed to match nothing.

[#3] What will be the result when non greedy repetition is used on the pattern /a+?b/ ?
Correct Answer

(A) Matches the letter b preceded by the fewest number of a’s possible

Explanation

Solution: Using non greedy repetition may not always produce the results you expect. /a+?b/ matches the letter b preceded by the fewest number of a’s possible.

[#4] What does the subexpression /java(script)?/ result in ?
Correct Answer

(A) It matches “java” followed by the optional “script”

Explanation

Solution: The subexpression /java(script)?/ matches “java” followed by the optional “script”.

[#5] What is the most essential purpose of parantheses in regular expressions ?
Correct Answer

(B) Define subpatterns within the complete pattern

Explanation

Solution: When a regular expression is successfullyy matched against a target string, it is possible to extract the portions of the target string that matched any particular paranthesized subpattern. The essential purpose of parantheses in regular expressions is to define subpatterns within the complete pattern.