20.6k views
0 votes
Assume that x is a char variable that has been declared and already given a value. Write an expression whose value is true if and only if x is an hexadecimal (Base 16) digit (0-9 plus A-F or a-f).

1 Answer

5 votes

Answer:

^[A-Fa-f0-9]+$

Step-by-step explanation:

The hexadecimal (Base 16) can contain 0-9, A-F, a-f and any of these can be the part of the Hexadecimal base 16 code.

In python we have the re.match function, and the syntax is as below:

re.match(pattern, string, flag=0). And we can use this function to check whether the entered char variable is a regex or not. Like:

re.match(pattern,x, flag=0)

User Krzysztow
by
5.5k points