Tapatalk

How to remove the entire file path from a file name using regular expressions?

How to remove the entire file path from a file name using regular expressions?

1002
Power UserPower User
1002

    Jan 15, 2019#1

    Is there a way to remove the entire file path from a file using regular expressions?

    I have a very long list of file names with path that I keep at cloud and it repeat every folder name for each file.
    I need to remove that to compare with other list.

    My list is like this:

    Code: Select all

    MEGAsync/Bonus do Mega/data/1Password for Windows v.4.6.2.625_arquivos/fontawesome-webfont.svg
    MEGAsync/Bonus do Mega/data/1Password for Windows v.4.6.2.625_arquivos/fontawesome-webfont.ttf
    MEGAsync/Bonus do Mega/data/1Password for Windows v.4.6.2.625_arquivos/fontawesome-webfont.woff
    MEGAsync/Bonus do Mega/data/1Password for Windows v.4.6.2.625_arquivos/fontawesome-webfont.woff2
    MEGAsync/Bonus do Mega/data/1Password for Windows v.4.6.2.625_arquivos/icomoon.eot
    MEGAsync/Bonus do Mega/data/1Password for Windows v.4.6.2.625_arquivos/icomoon.svg
    MEGAsync/Bonus do Mega/data/1Password for Windows v.4.6.2.625_arquivos/icomoon.ttf
    MEGAsync/Bonus do Mega/data/1Password for Windows v.4.6.2.625_arquivos/icomoon.woff
    MEGAsync/Bonus do Mega/data/1Password for Windows v.4.6.2.625_arquivos/icons.png
    MEGAsync/Bonus do Mega/data/1Password for Windows v.4.6.2.625_arquivos/icons_001.png
    MEGAsync/Bonus do Mega/data/1Password for Windows v.4.6.2.625_arquivos/index.css
    MEGAsync/Bonus do Mega/data/1Password for Windows v.4.6.2.625_arquivos/index.dat
    MEGAsync/Bonus do Mega/data/1Password for Windows v.4.6.2.625_arquivos/index.html
    MEGAsync/Bonus do Mega/data/CB broken on Firefox 48+/mem5yags126mizpba-un_r8oxuhpoqc.woff2
    MEGAsync/Bonus do Mega/data/CB broken on Firefox 48+/mem5yags126mizpba-unirkouehpoqc.woff2
    MEGAsync/Bonus do Mega/data/CB broken on Firefox 48+/mem5yags126mizpba-unirkouuhp.woff2
    MEGAsync/Bonus do Mega/data/CB broken on Firefox 48+/mem5yags126mizpba-unirkovuhpoqc.woff2
    MEGAsync/Bonus do Mega/data/CB broken on Firefox 48+/mem5yags126mizpba-unirkox-hpoqc.woff2
    MEGAsync/Bonus do Mega/data/CB broken on Firefox 48+/mem5yags126mizpba-unirkoxehpoqc.woff2
    MEGAsync/Bonus do Mega/data/CB broken on Firefox 48+/mem5yags126mizpba-unirkoxohpoqc.woff2
    MEGAsync/Bonus do Mega/data/CB broken on Firefox 48+/mem5yags126mizpba-unirkoxuhpoqc.woff2
    MEGAsync/Bonus do Mega/data/CB broken on Firefox 48+/mem8yags126mizpba-ufuz0bbck.woff2
    MEGAsync/Bonus do Mega/data/CB broken on Firefox 48+/mem8yags126mizpba-ufvp0bbck.woff2
    MEGAsync/Bonus do Mega/data/CB broken on Firefox 48+/mem8yags126mizpba-ufvz0b.woff2
    MEGAsync/Bonus do Mega/data/CB broken on Firefox 48+/mem8yags126mizpba-ufw50bbck.woff2
    MEGAsync/Bonus do Mega/data/CB broken on Firefox 48+/mem8yags126mizpba-ufwj0bbck.woff2
    MEGAsync/Bonus do Mega/data/CB broken on Firefox 48+/mem8yags126mizpba-ufwp0bbck.woff2
    Desired output would be like this:

    Code: Select all

    fontawesome-webfont.svg
    fontawesome-webfont.ttf
    fontawesome-webfont.woff
    fontawesome-webfont.woff2
    icomoon.eot
    icomoon.svg
    icomoon.ttf
    icomoon.woff
    icons.png
    icons_001.png
    index.css
    index.dat
    index.html
    mem5yags126mizpba-un_r8oxuhpoqc.woff2
    mem5yags126mizpba-unirkouehpoqc.woff2
    mem5yags126mizpba-unirkouuhp.woff2
    mem5yags126mizpba-unirkovuhpoqc.woff2
    mem5yags126mizpba-unirkox-hpoqc.woff2
    mem5yags126mizpba-unirkoxehpoqc.woff2
    mem5yags126mizpba-unirkoxohpoqc.woff2
    mem5yags126mizpba-unirkoxuhpoqc.woff2
    mem8yags126mizpba-ufuz0bbck.woff2
    mem8yags126mizpba-ufvp0bbck.woff2
    mem8yags126mizpba-ufvz0b.woff2
    mem8yags126mizpba-ufw50bbck.woff2
    mem8yags126mizpba-ufwj0bbck.woff2
    mem8yags126mizpba-ufwp0bbck.woff2

    11327
    MasterMaster
    11327

      Jan 15, 2019#2

      Find what: .*/
      Replace with: empty string (nothing)
      Regular Expressions: Perl
      It's impossible to lead us astray for we don't care even to choose the way.

      1002
      Power UserPower User
      1002

        Jan 15, 2019#3

        Thank you, Ovg. Topic solved.

        How it could be so easy?

        11327
        MasterMaster
        11327

          Jan 15, 2019#4

          Try www.regex101.com - online tester with explanations

          www.regular-expressions.info also useful information.
          It's impossible to lead us astray for we don't care even to choose the way.

          1002
          Power UserPower User
          1002

            Jan 15, 2019#5

            Excellent!

            Many thanks for the links.

            6,685587
            Grand MasterGrand Master
            6,685587

              Jan 16, 2019#6

              At Gabarito, see this post which explains why this simple greedy expression removes everything up to last forward slash on a line whereby it would be a bit better to use ^.*/ to explicitly start every search at beginning of a line.
              Best regards from an UC/UE/UES for Windows user from Austria

              1002
              Power UserPower User
              1002

                Jan 16, 2019#7

                Thank you, Mofi.

                Regular Expressions is a wonderful world and I try to handle better whenever I can.
                My big problems is when it requires two passes or two ways to use parameters/variables inside the same expression, like a back reference.
                But the solutions you both are giving here was a big surprise for me. I thought that many "/" inside the path would ask for back reference feature and I became afraid just to try it.

                This forum is a nice school and I come back often to see if something new shown up here.