2021年3月22日星期一

How to get the preceding sentence after "\v"?

Here's my text file:

\v 1 The book of the generation of Jesus Christ,  the son of David, the son of Abraham.  \v 2 Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judas and his brethren;  \v 3 And Judas begat Phares and Zara of Thamar;  and Phares begat Esrom; and Esrom begat Aram;  \v 4 And Aram begat Aminadab; and Aminadab begat Naasson; and Naasson begat Salmon;  \v 5 And Salmon begat Booz of Rachab; and Booz begat Obed of Ruth; and Obed begat Jesse;  

I want to capture the sentence from \v to the next \v.

Here's my code idea so far:

mylines = []  pattern = re.compile(r"(\\v)|(.*?)|(\\v)")  with open ('file.txt', 'rt', encoding='utf-8') as myfile:      for line in myfile:          if pattern.search(line) != None:              mylines.append(line.rstrip('\n'))    for element in mylines:      print(element)  
https://stackoverflow.com/questions/66756165/how-to-get-the-preceding-sentence-after-v March 23, 2021 at 09:49AM

没有评论:

发表评论