This is my text format, I want to pass regex into this data.
As I have created one regex but it doesn't work.
(\S+)\s+(\d+.\d+)|(\S+)\s+(=\d+.\d+)
It does not give me my expected output:
this data is in a TXT file, and there are many spaces before the word start
i attached the code for how i am reading a TXT file and how I use this regex in my code
Please help me
HUWAN DIAGNOSTICO CENTER
epoc BGEM BLACk ASD
Patient ID: ALEN KON
Date & Time: 22 May-45 7:49:73
Results: Gases+
hUbo2 21.8. ssol/t vsdw
AE(k) =3.0 asdsddf/as
Cat+ 1.1 fasdl/ aoKw
Glu 38
Dac < 0.30
DH 7.350 - 7.450
iKo2 35.0 —- 48.0
LE(dcf) 2.0- 3.0
Lp+ 138 ~ 146
C1- 98 - 107 hjkkl/asL
LKu 74 ~ 100
Arsa 9.51 - 1.19
s$92 94.0 - 98.0 %
Sample type: Unspecified
Hemodi lution: No
Height: Not entered
Comments: Operator: user
Expected output:
dictionary (key:list of values)
Keys Values
hUbo2 21.8
AE(k) 3.0
Cat+ 1.1
Glu 38
Dac 0.30
DH 7.350 7.450
iKo2 35.0 48.0
LE(dcf) 2.0 3.0
Lp+ 138 146
C1- 98 107
LKu 74 100
Arsa 9.51 1.19
s$92 94.0 98.0
# code for How i read my txt file
for i, line in enumerate(open(mytext_file)):
for match in re.finditer(pattern, line):
try:
abcd = float(match.group(2).strip())
print('%s: %s' % (match.group(1), abcd))
except Exception:
pass
^[^\S\r\n]*(\S+)[^\d\r\n]+(\d+(?:\.\d+)?)[^\d\r\n]*(\d+(?:\.\d+)?)?regex101.com/r/A3TKt9/1