Regular expression for a hexadecimal number?

后端 未结 11 1622
旧巷少年郎
旧巷少年郎 2020-11-29 02:56

How do I create a regular expression that detects hexadecimal numbers in a text?

For example, ‘0x0f4’, ‘0acdadecf822eeff32aca5830e438cb54aa722e3’, and ‘8BADF00D’.

11条回答
  •  感情败类
    2020-11-29 03:51

    Just for the record I would specify the following:

    /^[xX]?[0-9a-fA-F]{6}$/
    

    Which differs in that it checks that it has to contain the six valid characters and on lowercase or uppercase x in case we have one.

提交回复
热议问题