假如a.txt的开始和结尾都不知道有多少行,如何查找到并提取字符串"d7dhsjw8eieew323ew"
a.txt:
....
South Dakota is a state located in the Midwestern region of the United States:
d7dhsjw8eieew323ew
SD stock chart on Yahoo! Finance. Change the date range.
...
字符串"d7dhsjw8eieew323ew"每次都不一样
想提取...f the United States:到SD stock chart o...之间的字符串"d7dhsjw8eieew323ew",但字符串"d7dhsjw8eieew323ew"每次都不一样的,行号也不确定,用grep太麻烦吧。
追答以上为范例。这个subprocess.call默认是直接显示grep运行结果,如果想处理grep的结果,可以用subprocess.check_output
抱歉,我没阐述清楚,字符串"d7dhsjw8eieew323ew"是变量,每次都不一样,这方法就不行了吧?
追答将task_string传参进去不就行了?
import sys
task_string = sys.argv[1]
消息发了,你写的这句我看不懂啊
追答已经通过消息,回复你了,包括那句最关键的代码。
另外,顺便:
曰 拟 嘛 柏 渡,正常的正则表达式,都误判,都不给发布。而且还无法重新修改。拷 !!