正则表达式从文本中排除时间

regex excluding time from text

我想使用正则表达式从下面的文本中提取时间。

文本:“媒体:几分钟前,3:25 pm uts”

正则表达式模式 select 仅一次(例如:3:25)来自上面的文本?

使用正则表达式 /\b[0-9]+:[0-9]+\b/。说明:

  • \b - 单词边界
  • [0-9]+ - 1+ 位数
  • : - 冒号
  • [0-9]+ - 1+ 位数
  • \b - 单词边界

我不知道你在selenium中的具体用途,但这里有一个例子:

src = 'Media: a few minutes ago, 3:25 pm uts'
pattern = re.compile(r'(\b[0-9]+:[0-9]+\b)')
match = pattern.search(src)
print match.groups()[0]

输出:

3:25