What will the console output be when matching against the regex /[A-Z]/g in the string 'The quick brown fox jumps over the lazy dog. It barked.'?

Prepare for the Salesforce JavaScript Developer I Certification Exam. Utilize interactive quizzes, flashcards, and detailed explanations for each question. Boost your confidence and ace your exam effortlessly!

When using the regular expression /[A-Z]/g to match against the string 'The quick brown fox jumps over the lazy dog. It barked.', the regex is designed to find all uppercase letters in the string.

The character class [A-Z] matches any single uppercase letter from A to Z. The global flag "g" ensures that the regex searches through the entire string for all occurrences of uppercase letters, not just the first one.

In the provided string, the uppercase letters are 'T' from "The" and 'I' from "It." As the regex scans the string, it identifies both of these uppercase letters. Because the global flag is applied, both matches are collected and returned as an array. Therefore, the output will be an array containing both matched uppercase letters: ["T", "I"].

This demonstrates how regex searches can be effectively utilized to extract specific patterns from strings, and the global flag allows for a comprehensive search throughout the entire text.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy