繁体   English   中英

我怎样才能得到一个我不知道但知道前后单词的单词?

[英]How can I get a word that I don't know but knowing the words after and before?

我有一个字符串

" 89 o/t rep hi my name is hi my helo, 123, A, 89 o/d rep 129 / 314 judge asdfff"

我想让129 / 314知道它后面的词总是"judge"而前面的词是"89 o/d rep"

before = '89 o/d rep'
after = 'judge'
b = s.find(before)
a = s.find(after)
print(s[b+len(before):a])

使用正则表达式:

re.search("89 o/d rep (.*?) judge", s)[1]

在线尝试!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM