[英]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.