First I search for the numbers, and replace found with regexp.
Then take the changed string (?) and search for the spaces and replace found with regexp.
However I get wrong results.
test0 = This book id 0076 has 6782e6a
test1 = This book id 0076 has 0xef34a
I used following regular expression:
b = re.sub(r"(0x[a-fA-F0-9]+|\d+)","[0-9]*", test0)
c = re.sub(r'[(\s)*]','[^\s"]*',b)
My output:
test0
b = This book id [0-9]* has [0-9]*e[0-9]*a
c = This[^\s]*book[^\s]*id[^\s]*[0-9][^\s]*[^\s]*has[0-9][^\s]*e[0-9][^\s]*a
test1
b = This book id [0-9]* has [0-9]*
c = This[^\s]*book[^\s]*id[^\s]*[0-9][^\s]*[^\s]*has[0-9][^\s]*
Expected output:
test0
b = This book id [0-9]* has [0-9]*
c = This[^\s]*book[^\s]*id[^\s]*[0-9]*[^\s]*has[^\s]*[0-9]*
test1
b = This book id [0-9]* has [0-9]*
c = This[^\s]*book[^\s]*id[^\s]*[0-9]*[^\s]*has[^\s]*[0-9]*