python正则表达式从绝对路径中取文件名出来不加后缀(txt)

 1 正则表达式[^\\/:*?"<>|\r\n]+$    ---->取文件名包括后缀
 2 e.g.  >>>D:\PyCharm 2018.2.4\pythonWork\venv\Scripts\python.txt
 3         ->python.txt
 4 
5 正则表达式(.+?)\.txt ---->取上次结果去掉后缀 6 e.g. >>>python.txt 7 ->python

8 部分代码应用截取>>> 9 def send(): 10 sendfile = tk.Tk() 11 sendfile.withdraw() 12 13 file_path = filedialog.askopenfilename() 14 print(file_path) 15 16 newName = re.findall(r'[^\\/:*?"<>|\r\n]+$',file_path) 17 newName = re.findall(r'(.+?)\.txt',newName[0]) 18 19 os.system('python markup.py < %s > d:/%s.html '%(file_path,newName[0]))

猜你喜欢

转载自www.cnblogs.com/ZhangYuniang/p/10547066.html