Home > Back-end >  Regular Expression to match string starting with a specific word followed by digit [closed]
Regular Expression to match string starting with a specific word followed by digit [closed]

Time:09-29

I need to search specific words from logs. I need to find if there is any keywords like LEFT: , this value should always be less than 44 for example logs can have

(0:0)    abcd qwerty:[12345]    abcdef: 4455    LEFT: 33
(0:1)    xyzz abcde:[98765]     pqlmn: 1122     LEFT: 19
(0:2)    pqrs xyzz:[87694]      rtylg: 0099     LEFT: 54

So I need to find if LEFT: <value less than 44> , if yes then send true else false or if we can store them in set or list in python.

CodePudding user response:

Here is your regex solution to get the number after LEFT

Based on said solution above, here is some untested python code which may be close to your final solution

    import re
    for line in open('m.txt'):
        match = re.search('LEFT: (\d )', line)        
        if match:
            value = int(match.group(1))
            print(value < 44)
  • Related