Check if a string is hexadecimal

后端 未结 11 1457
说谎
说谎 2020-12-13 06:14

I know the easiest way is using a regular expression, but I wonder if there are other ways to do this check.

Why do I need this? I am writing a Python script that re

11条回答
  •  北海茫月
    2020-12-13 06:39

    Since all the regular expression above took about the same amount of time, I would guess that most of the time was related to converting the string to a regular expression. Below is the data I got when pre-compiling the regular expression.

    int_hex  
    0.000800 ms 10  
    0.001300 ms 100  
    0.008200 ms 1000  
    
    all_hex  
    0.003500 ms 10  
    0.015200 ms 100  
    0.112000 ms 1000  
    
    fullmatch_hex  
    0.001800 ms 10  
    0.001200 ms 100  
    0.005500 ms 1000
    

提交回复
热议问题