new Regex(@"(((?!\\).)+)(?=\\?)\\?$", RegexOptions.Singleline)
new Regex(@"([^\\]+)(?=\\?)\\?$", RegexOptions.Singleline)
源数据:
C:\Program Files\WindowsPowerShell\Configuration\Registration\
结果数据
| 0 | 1 | 2 |
| Registration\ | Registration | n |
取$1即可
本文介绍了一种使用正则表达式从特定路径中提取有用信息的方法。通过两个具体的正则表达式实例,展示了如何匹配并获取路径中的关键部分。这些技巧对于处理文件路径等字符串非常实用。
new Regex(@"(((?!\\).)+)(?=\\?)\\?$", RegexOptions.Singleline)
new Regex(@"([^\\]+)(?=\\?)\\?$", RegexOptions.Singleline)
源数据:
C:\Program Files\WindowsPowerShell\Configuration\Registration\
结果数据
| 0 | 1 | 2 |
| Registration\ | Registration | n |
取$1即可
5354

被折叠的 条评论
为什么被折叠?
