146k views
3 votes
In regex, what does the hyphen (-) and the dot (.) mean?

Option 1: Hyphen represents a range, dot matches any character
Option 2: Hyphen matches a literal hyphen, dot represents any digit
Option 3: Hyphen represents any character, dot matches a literal dot
Option 4: Hyphen is a wildcard, dot matches a range

1 Answer

1 vote

Final answer:

In regex, a hyphen (-) is used to represent a range of characters within a character class, and a dot (.) is used to match any single character except newline characters. Option 1 is correct.

Step-by-step explanation:

In regex, or regular expressions, a hyphen (-) and a dot (.) have specific meanings. A hyphen is used in character classes to denote a range of characters. For example, a-z represents all lowercase letters. The dot, on the other hand, is a special character that matches any single character except newline characters. For instance, the regex .a matches any two-character string that ends with 'a', such as 'ba' or '3a'.

Given the options, Option 1 is correct: Hyphen represents a range, dot matches any character. This means that in the context of numbers, if you wanted to create a regex pattern to match any digit, you could use a range with hyphens like 0-9. To match any character including digits, you would use a dot.

User ARZ
by
7.9k points