2024-04-26 23:31:41 发布
网友
试图在大量文本blob中找到一个模式“todestinationlocation”。 使用以下方法:
pattern = re.compile("to (.*)") string = #text blob pattern.search(string) # When I see the output >>> _.group(1) DestinationLocation blah blah blah ...
如何从捕获的文本中只提取“destinationLocation”?在
您想找到一个只由字母字符组成的单词,长度为1或更多,而不包含以下空格,因此请使用\w+(长度为1+的单个alpha):
\w+
pattern = re.compile("to (\w+)")
现在,如果单词实际上是words(比如to the mall),那么您将需要一些字符来指示单词序列的结尾,比如to the mall.(点限制器),以及带有可用字符集的include空格,以点结尾:
to the mall
to the mall.
您想找到一个只由字母字符组成的单词,长度为1或更多,而不包含以下空格,因此请使用
\w+
(长度为1+的单个alpha):现在,如果单词实际上是words(比如
^{pr2}$to the mall
),那么您将需要一些字符来指示单词序列的结尾,比如to the mall.
(点限制器),以及带有可用字符集的include空格,以点结尾:相关问题 更多 >
编程相关推荐