【发布时间】:2018-05-01 21:33:34
【问题描述】:
我有一个句子要解析以检查某些条件:
a) 如果有一个句点,并且它后面是一个空格,然后是一个小写字母
b) 如果在没有相邻空格的字母序列中存在一个句点(即 www.abc.com)
c) 如果有一个句点后跟一个空格,后跟一个大写字母,前面是一个简短的标题列表(即先生、博士、夫人)
目前我正在遍历字符串(行)并使用 next() 函数来查看下一个字符是空格还是小写等。然后我只是循环遍历该行。但是我将如何检查 next, next 字符是什么?我怎样才能找到以前的?
line = "This is line.1 www.abc.com. Mr."
t = iter(line)
b = next(t)
for i in line[:len(line)-1]:
a = next(t)
if i == "." and (a.isdigit()): #for example, this checks to see if the value after the period is a number
print("True")
任何帮助将不胜感激。谢谢。
【问题讨论】:
标签: python string parsing iterator