以下是我在正则表达式中使用的文本。我想抓住## Player Stats和## Goalie Stats
之间的所有内容[](#startinjuredreserve)
##Injured Reserve
|Position|Player|Salary|
|:-|:-|:-|
|RD|Oscar Fantenberg|$850,000|
|LW|Antoine Roussel|$3,000,000|
[](#endinjuredreserve)
[](#startmagicalbotarea)
##Schedule
|Date|Time|Opponent|TV/Score|
|::|::|::|::|
|15 Oct|19:00|vs [Detroit Red Wings](/r/detroitredwings "Detroit Red Wings")|**W 5-1**|
|17 Oct|17:00|@ [St. Louis Blues](/r/stlouisblues "St. Louis Blues")|**W 4-3**|
|19 Oct|10:00|@ [New Jersey Devils](/r/devils "New Jersey Devils")|L 1-0|
|**Today**|10:00|@ [New York Rangers](/r/rangers "New York Rangers")|**W 3-2**|
|22 Oct|16:30|@ [Detroit Red Wings](/r/detroitredwings "Detroit Red Wings")|SN360|
|25 Oct|19:00|vs [Washington Capitals](/r/caps "Washington Capitals")|SN1|
|28 Oct|19:00|vs [Florida Panthers](/r/floridapanthers "Florida Panthers")|SNP|
##Pacific Standings
|Team|GP|W|L|OTL|PTS|Streak
|::|::|::|::|::|::|::|
|[Edmonton Oilers](/r/edmontonoilers "Edmonton Oilers")|8|7|1|0|14|W2|
|[Anaheim Ducks](/r/anaheimducks "Anaheim Ducks")|8|6|2|0|12|W2|
|[Vegas Golden Knights](/r/goldenknights "Vegas Golden Knights")|9|6|3|0|12|W2|
|[Vancouver Canucks](/r/canucks "Vancouver Canucks")|8|5|3|0|10|W1|
|[Arizona Coyotes](/r/coyotes "Arizona Coyotes")|7|4|2|1|9|W3|
|[Calgary Flames](/r/calgaryflames "Calgary Flames")|9|4|4|1|9|L1|
|[San Jose Sharks](/r/sanjosesharks "San Jose Sharks")|8|3|5|0|6|L1|
|[Los Angeles Kings](/r/losangeleskings "Los Angeles Kings")|8|3|5|0|6|W1|
##Player Stats
Player|GP|G|A|P|+/-|PIM|
|:|::|::|::|::|::|::|
|Miller|8|4|4|**8**|5|4|
|Pettersson|8|2|6|**8**|4|0|
|Boeser|8|2|5|**7**|4|0|
|Edler|8|3|3|**6**|-1|10|
|Sutter|8|2|3|**5**|1|7|
|Pearson|8|2|2|**4**|-4|2|
|Tanev|8|1|3|**4**|1|0|
|Hughes|8|1|3|**4**|1|2|
|Horvat|8|2|1|**3**|0|2|
|Leivo|8|1|2|**3**|1|2|
##Goalie Stats
|Goalie|GP|W|L|SV%|GAA|SO|
|:|::|::|::|::|::|::|
|Markstrom|5|3|2|0.932|2.19|0|
|Demko|3|2|1|0.943|1.64|0|
*****
Updated at: 20 Oct 2019, 03:12 PM PST
*****
[](#endmagicalbotarea)
##Filter Options
- If you want to block a certain type of posts, click one of the link filters below
- [No Shitpost/Memes](https://nm.reddit.com/r/canucks/#nm)
- [No Fan Content](https://nf.reddit.com/r/canucks/#nf)
- [No Memes or Fan Content](https://mf.reddit.com/r/canucks/#mf)
- [Reset Filter](https://reddit.com/r/canucks/)
## Links & Resources
- /r/hockey
- /r/UticaComets
- /r/TheAthleticVAN
- [Canucks Capfriendly](https://www.capfriendly.com/teams/canucks)
- [Canucks.com](https://www.nhl.com/canucks)
- [Canucks Official Twitter](https://twitter.com/canucks)
- [Canucks Official YT Channel](http://www.youtube.com/user/Canucks)
- [Sportsnet 650 Vancouver](http://www.sportsnet.ca/650/)
- [TSN 1040](http://www.tsn.ca/radio/vancouver-1040-i-1410)
- [**Join /r/Canucks Discord!**] (https://discord.gg/UTZ5Vrb)
## Subreddit Wiki
- [Rules and Guidelines](/r/canucks/wiki/rules)
- [Streaming Guide](/r/canucks/wiki/streaming)
- [Attending a Canucks Game?](/r/canucks/comments/2u5lxr/so_you_wanna_go_to_a_canucks_game_eh_faq_for/)
- [Canucks Resources](/r/canucks/wiki/resources)
- [Meme Hall of Fame](/r/canucks/wiki/memes)
- [AMA Archive](/r/canucks/wiki/amas)
- [**Nostalgia Corner**](https://www.reddit.com/r/canucks/wiki/nostalgia-corner)
https://regex101.com/r/te4DRa/1
正如您在regex101上看到的那样,它正确地捕获了## Players Stats和## Goalie Stats之间的12行,但是当我在Python中运行以下代码时,会返回None
sidebar = self.r.subreddit(self.SUBREDDIT).wiki['config/sidebar'].content_md
test = re.match('##Player Stats\n(.*?)##Goalie Stats', sidebar, flags=re.DOTALL)
print(sidebar)
sidebar
正确地获取了文本。
答案 0 :(得分:0)
使用findall:
re.findall(r'##Player Stats\n(.*?)##Goalie Stats',text,flags=re.DOTALL)
请不要忘记在表示原始表示的模式之前的r
Ref:What exactly do “u” and “r” string flags do, and what are raw string literals?