Moim celem jest, aby przeczytać ciąg i gdzie znaleźć całkowitą lub liczbę szesnastkową kiedykolwiek zastąpi że z „[0-9]” mój ciąg jest:Wyrażenie regularne na szesnastkowy i inne ciągi
a = hello word 123 with the 0x54673ef75e1a
a1 = hello word 123 with the 0xf
a2 = hello word 123 with the 0xea21f
a3 = hello word 123 with the 0xfa
próbowałem z następujących powodów:
b = re.sub(r"(\d+[A-Fa-f]*\d+[A-Fa-f]*)|(\d+)","[0-9]",a)
uzyskać następujące dane wyjściowe:
hello word [0-9] with the [0-9]x[0-9]a
hello word [0-9] with the [0-9]xf
hello word [0-9] with the [0-9]xea[0-9]
hello word [0-9] with the [0-9]xfa
ale outpu t powinno być tak:
hello word [0-9] with the [0-9]
hello word [0-9] with the [0-9]
hello word [0-9] with the [0-9]
hello word [0-9] with the [0-9]
Użyj 'R '(0 x [A-Fa, F \ d] + | \ D +)'' jako regexpa. – Blender