正则表达式最后一次出现?

2024-09-30 14:30:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图抓住最后一个反斜杠后的最后一部分
我需要\Web_ERP_Assistant(带\

我的想法是:

C:\Projects\Ensure_Solution\Assistance\App_WebReferences\Web_ERP_WebService\Web_ERP_Assistant


\\.+?(?!\\)      //  I know there is something with negative look -ahead `(?!\\)`

但是我找不到它

^{}


Tags: webapperpiswithsomethingprojectsthere
3条回答

其中一个对我有效的方法是:

.+(\\.+)$

Try it online!

说明:

.+     - any character except newline
(      - create a group
 \\.+   - match a backslash, and any characters after it
)      - end group
$      - this all has to happen at the end of the string

消极展望是正确的答案,但可以写得更清楚,如:

(\\)(?!.*\\)

这将查找\的出现,然后在未匹配的检查中,查找任意数量的字符,后跟您不希望看到的字符。因为它是负数,所以只有在找不到匹配项时才匹配

您的消极前瞻解决方案如下:

\\(?:.(?!\\))+$

here on Regexr

相关问题 更多 >