'Need a regular expression to check if pattern match

I need a regular expression which will check if the first 2 characters are 0x and next 4 characters will be Alphanumeric characters

Example:  0x13H3

It should exceed more that 6 characters.

This seems to be not working REGEXP_LIKE(string, '[0x]A-Z0-9')

Can anyone please guide me ?



Solution 1:[1]

Try this: REGEXP_LIKE(string, '0x[A-Z0-9]{4}')

[] is a character class, which states that only the chars or range described inside it can be matched. So your regex pattern: [0x]A-Z0-9, says to match either 0 or x, litterally followed by A-Z0-9, so it would have matched either '0A-Z0-9' or 'xA-Z0-9'.

Explanation:

0x[A-Z0-9]{4}

0x          matches 0x
[A-Z0-9]{4} matches uppercase and numbers four times

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1