我知道题目可能不清楚,所以我要更具体地描述我的问题。你知道吗
这里有两个字符串:
“基金资产”
“基金寻求通过至少投资其总资产的80%来实现其投资目标”
我的目标是第一个字符串,因此我使用以下正则表达式代码来获取它:
r'fund+.+asset+'
我之所以在“fund+”和“asset+”之间使用“.+”,是因为在其他情况下,“fund”和“asset”之间可能有额外的词,例如“fund total asset”。所以我必须用“.+”来确保我能找到所有可能的目标。你知道吗
然而,第二根绳子,也会被抓住,显然不是我的目标。所以我想把字符数限制在‘基金’和‘资产’之间。你知道吗
伪代码如下:
r'fund+(.+<=6)asset+'
因此,我将“fund”和“asset”之间的字符数限制为不超过6个。你知道吗
regex能做到吗?谢谢你的帮助!:)
您可以使用^{} operator :
在“基金”和“资产”之间匹配1到8个任意字符。你知道吗
下面是一个演示:http://refiddle.com/refiddles/56d65e8b75622d6956086500
用curly braces检查重复次数:
匹配
fund assets
和fund total assets
,但不匹配fund seeks to achieve its investment objective by investing at least 80% of its total assets
:7
用于fund total assets
示例-total
长度为5个字符加上单词周围的两个空格。你知道吗相关问题 更多 >
编程相关推荐