<p>这种模式应该起到以下作用:</p>
<pre><code>(?P<event>(?P<outcome1>[^-]+?) vs (?P<outcome2>[^-]+) -.*?) -[^\b]*?(?P<date>(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) \d+/\d+(?:/\d+)?)[^.]*(?P<outcome1odds>\d+\.\d+)\s+(?P<time>\d+:\d+[AP]M)[^.]*(?P<outcome2odds>\d+\.\d+)
</code></pre>
<p>它很长,但作为交换,您可以使用<code>.groupdict()</code>函数直接获得所需的结果:</p>
<pre><code>print(re.match(pattern, text).groupdict())
</code></pre>
<hr/>
<p>分解:</p>
<pre><code>(?P<event> # in a named capture group, match...
(?P<outcome1> # outcome1, which is...
[^-]+? # all text up to...
)
vs # a literal " vs "
(?P<outcome2> # outcome2 is...
[^-]+ # all text up to...
)
- # the next literal " -"
.*? # still inside the "event" group, match until...
)
- # a literal " -"
[^\b]*? # skip forward to...
(?P<date> # the date, which is...
(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) # a weekday
\d+/\d+(?:/\d+)? # followed by digits separated with /
)
[^.]* # skip worward to...
(?P<outcome1odds>
\d+\.\d+ # a floating point number
)
\s+
(?P<time> # match the time, which is...
\d+:\d+ # digits separated with :
[AP]M # followed by AM or PM
)
[^.]* # skip to...
(?P<outcome2odds>
\d+\.\d+ # another floating point number
)
</code></pre>