一个正则表达式,在某个单词后面的括号内寻找数字

2024-09-25 08:38:52 发布

您现在位置:Python中文网/ 问答频道 /正文

这里有一个字符串,格式如下:

Board: [Qd 6c Kc 8s Ad]

Player STACKS5143 does not show cards.Bets: 0.15. Collects: 0. Loses: 0.15.

Player REAGANBUSH84 does not show cards.Bets: 0.15. Collects: 0. Loses: 0.15.

Player HossaRules does not show cards.Bets: 0. Collects: 0. Wins: 0.

Player xrayoki does not show cards.Bets: 0. Collects: 0. Wins: 0.

Player sykoteekho shows: High card A [7c 9c]. Bets: 3.29. Collects: 0. Loses: 3.29.

*Player Autobot shows: One pair of Ks [Ks Jh]. Bets: 3.29. Collects: 6.54. Wins: 3.25.

Game ended at: 2018/2/19 15:59:26

我只想在单词show之后找到括号内的数字

有办法吗?你知道吗

我在这里试过:(show.+ | \[.+\]) 但它似乎在拾起我不想要的其他括号。你知道吗

有什么好主意吗

谢谢你


Tags: 字符串board格式shownotshows括号cards
2条回答

这里是:

show.+\[([a-zA-Z0-9 ]+)\]

将只匹配“7c 9c”和“Ks Jh”作为组“$1”。你知道吗

演示:here

只要玩家的用户名中不允许有方括号,它甚至应该与名字中有“show”作为子字符串的玩家一起工作。你知道吗

  1. 看起来您需要shows作为关键字。你知道吗
  2. 以直线为基础,即不要跨越直线。你知道吗
  3. 单支架。你知道吗

试试shows.*?\[([^\[\]\r\n]*)\]

其中$1(组1)包含括号内容。你知道吗

相关问题 更多 >