There is a line like this:

AAA 356 125 [654:11233:1123] 255 255 255 [123]: abc

You need to pull out of this line this part: 123 , which is in [123]:

123 can be any other number (but only a number), at least one-digit, and at most three-digit ( 5 , 999 , 0 , 88 , etc).

I can't figure out regular expressions, something goes wrong all the time.

 line = 'AAA 356 125 [654:11233:1123] 255 255 255 [123]: abc' search = re.search('[(\d??)]:', line) # Пытался найти от 1 до 3 цифр между [ и ]: 

    2 answers 2

    123 can be any other number (but only a number), at least one-digit, and at most three-digit (5, 999, 0, 88, etc).

     >>> re.search(r'\[(\d{1,3})\]', line).group(1) '123' 

      You must first shield the character " [ ", this is done like this \ [
      then look for any number or character \ w
      if only number, then \ d
      and add how many of them can be + (plus) to the \] character and the character :
      and there you want what you do.
      '\ [\ w + \]:' is a regular expression
      '\ [\ d + \]:' - regular expression if only numbers

       import re line = 'AAA 356 125 [654:11233:1123] 255 255 255 [123]: abc' search = re.search('\[\w+\]:', line) s = search.group()[1:-2] print(s)