Regular expression HELP get multiply string

I am having difficult parse the specific string
[20221018.165317.401606][info]:[DL- UE[ 0]: Value= 0.000091 Mbps, Mcs= 4.0(Sigma= 0.0), Num= 1.4]

How do I get the string 20221018.165317.401606 Value= 0.000091 Mbps Mcs= 4.0 Num= 1.4

I only able to parse the first string the timedate


string="[20221018.165317.401606][info]:[DL- UE[ 0]: Value=    0.000091 Mbps, Mcs=  4.0(Sigma= 0.0), Num=   1.4]"
regex = re.compile(r'[2]\d{7}\.\d{6}\.\d{6}') #'[2] start with 2"\[([0-9.]+)\]", string)
match =
print( #20221018.165317.401606

I try with this \[([0-9.]+)\]([A-Z][a-z]{4}) not working, any idea to parse it
I try with this work ([0|1]\.\d[0-9]+) ==>0.000091 Mbps

I’d probably go with \[(\d+\.\d+\.\d+)\].*?(Value=[^]]+) and then use the contents of groups 1 and 2.

like this: m3 ='\[(\d+\.\d+\.\d+)\].*?(Value=[^]]+)', st2)

I try with this

m3 ='\[(\d+\.\d+\.\d+)\].*?(Value=[^]]+)', string)
#output: Value=    0.000091 Mbps, Mcs=  4.0(Sigma= 0.0), Num=   1.4

How to get the value, using split

If you mean the value after "Value=", then:

['Value=', '0.000091', 'Mbps,', 'Mcs=', '4.0(Sigma=', '0.0),', 'Num=', '1.4']
1 Like

HI do you know how to split like this:
string: [20221110.112127.316856][info]:[PDCP DL- ingress traffic: 0.000000(Mbps), egress traffic: 0.000000(Mbps)]

How can I split like [ ‘ingress traffic:’ , ‘0.000000(Mbps)’, ‘egress traffic:’, ‘0.000000(Mbps)’]

i try like this

str = "[20221110.112127.316856][info]:[PDCP DL- ingress traffic: 0.000000(Mbps), egress traffic: 0.000000(Mbps)]"
search3 ='ingress [^]]+', str) 

output:‘ingress traffic: 0.000000(Mbps), egress traffic: 0.000000(Mbps)’

How can i achieve like below result:

[ 'ingress traffic:' , '0.000000(Mbps)', 'egress traffic:', '0.000000(Mbps)']

Because there are multiple space so when using split with space will spit all the space, but i actually only want the second space

is there any solution to it?

i solve it

string2="[20221110.112127.316856][info]:[PDCP DL- ingress traffic: 0.000000(Mbps), egress traffic: 0.000000(Mbps)]"'(ingress [^(]+).+(egress [^(]+)',string2)
test=", "+
#ingress traffic: 0.000000, egress traffic: 0.000000
test1=test.replace(", ", ":").strip().split(':')
['ingress traffic', ' 0.000000', 'egress traffic', ' 0.000000']

Some remarks:

If I were doing this, I’d be inclined to match more rigidly. For
example, instead of just grabbing everything which is not an opening
bracket, grab the labels (eg “ingress traffic”), the delimiter (": ")
and the numeric parts (“0.000000”) specificly. Maybe even the units
inside the brackets. This avoids mismatching incorrectly/inappropriate
lines, and also makes it easier to deal with the matched parts.

Example (untested):

 (ingress traffic):\S+(\d+\.\d+)

This (a) matches your label specificly and (b) matches a number. It also
puts groups (the brackets) around the label and number; those groups are
then available in the match object directly (in your code, the
searchtest variable - the result of the call).

Then you can for example use the label as a key in a dict and convert
the numeric string to an actual number, eg:

 label =
 numeric =
 number = float(numeric)

Cameron Simpson

i used your method, is it like this:’(ingress traffic):\S+(\d+.\d+)', str)

but nothing is found, did I miss it?

Ahh… I’m an idiot. I mean \s (whitespace), not \S (nonwhitespace).
Try a lowercase s in the above regexp.

When you have that working, you can do things like a loop for the
various labels (to use the same code), or re.findall() with a pattern to
match any label, then look up the labels it finds (or just build a
dict with keys from all the labels).

Cameron Simpson

but I wish to do like this
[ ‘ingress traffic:’ , ‘0.000000(Mbps)’, ‘egress traffic:’, ‘0.000000(Mbps)’]

Well nothing says you need to put things into a dict, you can just append the label and the numeric part onto your list of results. And you can make the pattern for the numeric part include the bracketed unit (Mbps) as desired.


ok thanks for the help