What will be the output of the following snippet var str = The best things3 are free in life var pattern = new RegExp(a-z+0-9) var result = patternexec(str) consolelog(result) true s3 The best

Step 1: Understand the Regular Expression

The regular expression [a-z]+[0-9] searches for one or more lowercase letters ([a-z]+) followed by a single digit ([0-9]).

Step 2: Apply the Regular Expression to the String

The exec() method searches for the first match of the regular expression within the string “The best things3 are free in life”.

Step 3: Identify the Match

The regex engine finds “things3” as the first match because it consists of lowercase letters followed by a digit.

Step 4: Determine the Output

The exec() method returns an array containing the matched substring. If no match is found, it returns null.

Final Answer

things3

Read more here: Source link