regex removing filename from path

后端 未结 2 918
春和景丽
春和景丽 2021-02-06 06:49

How could I design a RegEx script which would remove a filename from a path? The trick is, the paths have all sorts of wrenches to throw into the works.

Paths can consis

相关标签:
2条回答
  • 2021-02-06 07:01

    You can use a simple regex like this:

    (.*\/).*
    

    Working demo

    enter image description here

    As you can see, the idea is to capture all the content to the last slash by using (.*\/) and discard the rest .*. Check the substitution section above.

    0 讨论(0)
  • 2021-02-06 07:15

    You can use this.

    [^\/]+$
    

    '$' matches the position at the end of the string while '[^/]+' matches any string that does not have any '/'.

    0 讨论(0)
提交回复
热议问题