There are two more repeating qualifiers. The question mark character, ?, matches either once or zero times;
you can think of it as marking something as being optional.
For example, home-?brew matches either 'homebrew' or 'home-brew'.

import re

str_list = ["u_ex200331.log", "u_ex200331_x.log", "u_ex200331_xxx.log", "u_ex203888_x_x.log"]

matchObj = [str for str in str_list if re.match('^(u_ex[0-9]{6}(_x)?\.log)$', str)]

print(matchObj)

结果输出为:

['u_ex200331.log', 'u_ex200331_x.log']

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
相关资源
相似解决方案