Python正则表达式记录

匹配NR UE Capability Information中的supportedGapPattern信息:

import re

ie = 'supportedGapPattern: 300000 [bit length 22, 2 LSB pad bits, 0011 0000  0000 0000  0000 00.. decimal value 786432]'
re_pattern = 'supportedGapPattern: ([a-zA-Z0-9]+) \[bit length (\d+), (\d+) LSB pad bits, .*'
matched = re.match(re_pattern, ie)

if matched:
    bit_len = int(matched.group(2))
    pad_len = int(matched.group(3))
    pattern = int(matched.group(1), 16) >> pad_len
    print(pattern, bit_len, pad_len)

你可能感兴趣的:(Python正则表达式记录)