Python 正则表达式从Windows路径中获取文件夹
2014-11-12 09:22
826 查看
<pre name="code" class="python">1. Regular Expression ^([a-zA-Z]:|\\\\[a-zA-Z0-9_.$ -]+\\[a-z0-9_.$ -]+)?((?:\\|^)(?:[^\\/:*?"<>|\r\n]+\\)+) eg. c:\folder\subfolder\file.ext Extract: \folder\subfolder\ \\server\share\folder\subfolder\file.ext Extract: \folder\subfolder\ 2. Python code import re subject = 'c:\\folder\\subfolder\\file.ext' match = re.search(r'^([a-zA-Z]:|\\\\[a-zA-Z0-9_.$ -]+\\[a-z0-9_.$ -]+)?((?:\\|^)(?:[^\\/:*?"<>|\r\n]+\\)+)', subject) if match: result = match.group(2) else: result = "" print result,
相关文章推荐
- Python 正则表达式验证Windows路径
- python获取Windows特殊文件夹路径
- Python 正则表达式提取Windows路径中文件名
- WindowsAPI使用详解——GetWindowsDirectory|GetSystemDirectory 获取操作系统文件夹的路径
- 采用正则表达式获取某路径下符合特定模式字符串的文件名
- Python练习代码 -- 字符串和正则表达式, 文件文件夹操作
- python读配置文件;正则表达式替换、切割字符串;获取当前时间
- python+正则表达式获取ed2k url
- 正则表达式获取网页中所有图片的路径
- 正则表达式验证文件路径(windows)
- ASP使用正则表达式批量分离编辑框中的图片从而获取图片路径
- Python 正则表达式提取windows盘符
- 使用Python正则表达式从文章中取出所有图片路径
- 怎么用正则表达式获取文章内容中的&lt;img标签和 src的路径
- 使用正则表达式写一个网页爬虫案例获取指定文档中的邮件地址保存到自己指定的文件夹中
- C# 实现读取本地某文件夹中的html文件,然后通过正则表达式获取input控件中的id值
- python26实例[根据正则表达式来清理文件夹]
- 使用python和正则表达式获取url,及总结
- C++获取windows特殊文件夹路径
- python+正则表达式获取ed2k url