Regular Expression, remove everything after last forward slash

后端 未结 5 769
逝去的感伤
逝去的感伤 2020-12-14 21:07

I\'m trying to use a regular expression within PowerShell to remove everything from the last slash in this string;

 NorthWind.ac.uk/Users/Current/IT/Surname,         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 22:09

    Here's another solution that doesn't require regular expressions:

    Take a substring of your string starting at the beginning of the string and ending before the index of the last slash in your string:

    PS> $indexoflastslash = ("NorthWind.ac.uk/Users/Current/IT/Surname, FirstName").lastindexof('/')
    PS> "NorthWind.ac.uk/Users/Current/IT/Surname, FirstName".substring(0,$indexoflastslash)
    

提交回复
热议问题