1. What is a regular expression in JavaScript?
Answer:
Explanation:
In JavaScript, a regular expression is a sequence of characters that forms a search pattern, which can be used for matching and manipulating strings.
2. How do you create a regular expression in JavaScript?
Answer:
Explanation:
Regular expressions in JavaScript can be created using the RegExp() constructor or by writing the pattern between forward slashes.
3. Which character in a regular expression means "match any character"?
Answer:
Explanation:
In regular expressions, the dot (.) character is used to match any single character except newline characters.
4. What does the '+' symbol represent in regular expressions?
Answer:
Explanation:
The '+' symbol in a regular expression indicates that the preceding character should be matched one or more times.
5. How do you indicate that a pattern should match the beginning of a string in a regular expression?
Answer:
Explanation:
The '^' symbol is used at the beginning of a regular expression to indicate that the match must start at the beginning of the string.
6. What does the '?' symbol mean in regular expressions?
Answer:
Explanation:
The '?' symbol in a regular expression means that the preceding character is optional and should be matched zero or one time.
7. How do you specify a range of characters in a regular expression?
Answer:
Explanation:
Square brackets [] are used in regular expressions to specify a range or a set of characters to match.
8. What is the function of the pipe '|' symbol in a regular expression?
Answer:
Explanation:
The pipe '|' symbol in a regular expression acts as a logical OR operator, allowing for the matching of one pattern or another.
9. How do you match a specific number of occurrences of a character in a regular expression?
Answer:
Explanation:
Curly braces {} in a regular expression are used to specify the exact number of times a character or a group of characters should be matched.
10. What does the '\d' symbol represent in a regular expression?
Answer:
Explanation:
The '\d' symbol in a regular expression is used to match any digit character, equivalent to [0-9].
11. How do you make a regular expression case insensitive in JavaScript?
Answer:
Explanation:
Adding the 'i' flag to a regular expression in JavaScript makes the pattern matching case insensitive.
12. What does the '\s' symbol represent in a regular expression?
Answer:
Explanation:
The '\s' symbol in a regular expression is used to match any whitespace character, including spaces, tabs, and line breaks.
13. How do you specify that a pattern should match the end of a string in a regular expression?
Answer:
Explanation:
The '$' symbol is used at the end of a regular expression to indicate that the match must occur at the end of the string.
14. What does the '\w' symbol represent in a regular expression?
Answer:
Explanation:
The '\w' symbol in a regular expression matches any word character, which includes letters, digits, and underscores.
15. How do you group parts of a regular expression?
Answer:
Explanation:
Parentheses () are used in regular expressions to group parts of the expression, which is useful for applying quantifiers to a group or for capturing groups in a match.