简体   繁体   English

如何在 Python 上使用 RE 获取 \ 字符右侧路径中的姓氏?

[英]How can I get the last name in a path next to the right of a \ character using RE on Python?

I have been trying to make a good regular expression that catches the last name (of a file or folder) for a given path, meaning that for instance, the following path:我一直在尝试制作一个好的正则表达式来捕获给定路径的姓氏(文件或文件夹),这意味着例如以下路径:

C:\Users\ResetStoreX\Pictures C:\Users\ResetStoreX\Pictures

Can be reduced to:可以简化为:

Pictures图片

What I have achieved so far is the following RE: (?:[^\\]\\)[^\\]*$到目前为止,我所取得的是以下 RE: (?:[^\\]\\)[^\\]*$

Which reduces the previous path to:这减少了以前的路径:

X\Pictures X\图片

Any ideas?有任何想法吗?

You almost had it.你几乎拥有它。 I removed the \ inside of the parentheses, if you want all backslashes to be captured.如果您希望捕获所有反斜杠,我删除了括号内的 \。

(?:[^\\])[^\\]*$

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 python 中获得第二天的名称 - How can I get the next day name in python 使用 Indexing 和 Splice() 获取 Python 中名字的前两个字符和姓氏的第一个字符: - Get first two character of first name AND first character of last name in Python using Indexing and Splice(): 如何在Python中使用RE将重复字符压缩为单个字符? - How can I compress repetitive characters to a single character using RE in Python? 如何正确应用 RE 以从给定路径获取姓氏(文件或文件夹的)并将其打印在 Python 上? - How to correctly apply a RE for obtaining the last name (of a file or folder) from a given path and print it on Python? 除了 Python 中的最后一个字符之外,如何获取字符串中的特定字符? - How can I get the specific character in string except the last one in Python? 在python中,如何删除也使用换行符的打印中的最后一个字符? 试过 rstrip() - In python, how can I remove the last character in a print that is also using line continuation? Tried rstrip() 如何使用 python 获取下个月和下个月的最后一个星期四日期 - How to get last Thursday date of next month and next of next month using python 如何覆盖 Python 中最后一个打印的字符 - How can I overwrite the last printed character in Python 当用户写名字和姓氏框时,我希望它使用 tkinter 和 python-docx 在单元格中打印它,我该怎么做? - When the user write the first name and the last name boxs I want it to get print it in cell using tkinter and python-docx, how can I do that? 如何使用Python获取进程名称 - How can I get process name using Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM