fork download
  1. str = '[2019-07-29 09:48:11,928] @hr.com [2] [AM] WARN'
  2. result = ''
  3. cnt = 0
  4. str.scan(/\[([^\]\[]*)\]/) { |match| result = match[0]; cnt +=1; break if cnt >= 2}
  5. puts result #=> 2
  6.  
Success #stdin #stdout 0s 6420KB
stdin
Standard input is empty
stdout
2