Want to remove everything after nth “/” from hyperlink in Notepad++ or Excel

前端 未结 2 928
情歌与酒
情歌与酒 2021-01-16 15:37

I need some help: looking for a way to remove everything after the nth occurrence (most likely 4th or 5th) of \"/\" in a hyperlink. For instance, if I have

         


        
相关标签:
2条回答
  • 2021-01-16 15:51

    Using Notepad++:

    • Ctrl+H
    • Find what: ^((?:[^/]*/){5}).*$
    • Replace with: $1
    • check Wrap around
    • check Regular expression
    • DO NOT CHECK . matches newline
    • Replace all

    Explanation:

    ^               : begining of lin
      (             : start group 1
        (?:         : start non capture group
          [^/]*     : 0 or more any character that is not a slash
          /         : a slash
        ){5}        : group must appear 5 times
      )             : end group 1
      .*            : 0 or more any character
    $               : end of line
    

    Replacement:

    $1          : content of group 1 (ie. everything before the 5th slash)
    

    Result for given example:

    https://www.forbes.com/forbes/welcome/
    
    0 讨论(0)
  • 2021-01-16 16:17

    Quite simple formula, although I agree with @Scott Holtzman that you should show some effort before posting question here. In Excel enter this formula in cell B1 if your links are in cell A1.

    =IFERROR(LEFT(SUBSTITUTE(A1,"/","~~~~",5),FIND("~~~~",SUBSTITUTE(A1,"/","~~~~",5),1)-1)&"/",A1)
    

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