Community
    • Login

    regex to remove part of a line with variable words

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    9 Posts 3 Posters 425 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Rockberto ManentiR
      Rockberto Manenti
      last edited by

      hi everyone.
      I have a series of text files from which I would like to remove a specific part of the text contained on some lines. Here’s an example.
      title “Smoke on the water (Deep Purple cover)”
      I would like it to become: title “Smoke on the water”

      or:
      title “the rover (Led Zeppelin cover)”
      it must become: title “the rover”

      the word cover is always present, the problem is that the name of the band before the word “cover” is never the same but that part of the text is always between the two brackets ()
      so basically I would like to understand which regex allows me to leave the first part of the line intact but makes the part that contains (artist name cover) disappear
      obviously “artist name” is variable but it is always preceded by the (
      I hope I explained myself…
      and thanks in advance

      CoisesC 1 Reply Last reply Reply Quote 0
      • CoisesC
        Coises @Rockberto Manenti
        last edited by Coises

        @Rockberto-Manenti said in regex to remove part of a line with variable words:

        so basically I would like to understand which regex allows me to leave the first part of the line intact but makes the part that contains (artist name cover) disappear
        obviously “artist name” is variable but it is always preceded by the (

        Try:
        \h*\([^\r\n)]* cover\)$

        That should work if the parenthesized part you want to remove is always the last thing on the line and if none of the band names include a closing parenthesis.

        Rockberto ManentiR 2 Replies Last reply Reply Quote 1
        • Rockberto ManentiR
          Rockberto Manenti @Coises
          last edited by

          @Coises
          thanx for reply. Yes the line ends alway with:
          (artist name cover)

          I try immediatelyand I’m back here to confirm that it works. Wait…

          1 Reply Last reply Reply Quote 0
          • Rockberto ManentiR
            Rockberto Manenti @Coises
            last edited by

            @Coises
            it doesn’t work, it didn’t find any results.
            I selected regular expression

            PeterJonesP 1 Reply Last reply Reply Quote 0
            • PeterJonesP
              PeterJones @Rockberto Manenti
              last edited by

              @Rockberto-Manenti said in regex to remove part of a line with variable words:

              it doesn’t work, it didn’t find any results.

              Then your data doesn’t match what you showed us, because it works on your example data
              7bdee44b-334f-419c-bb31-16813cc310f0-image.png

              Rockberto ManentiR 1 Reply Last reply Reply Quote 0
              • Rockberto ManentiR
                Rockberto Manenti @PeterJones
                last edited by

                @PeterJones said in regex to remove part of a line with variable words:

                Then your data doesn’t match what you showed us, because it works on your example data

                you are absolutely right. I made a mistake in giving the example but I didn’t think it would have an effect.
                actually the text in the files is written like this:
                title “the rover (led zeppelin cover)”
                which should become:
                title “the rover”

                I didn’t think the quotation marks " would have an effect on the regular expression
                sorry… mea culpa…
                without ", in fact, your expression works…
                but the quotation marks must remain… how should the expression be changed?
                thanks in advance

                Rockberto ManentiR 1 Reply Last reply Reply Quote 1
                • Rockberto ManentiR
                  Rockberto Manenti @Rockberto Manenti
                  last edited by

                  I try with
                  \h*([^\r\n)]* cover)"$

                  and replace with "

                  now it works!
                  I don’t know if it’s right, but since it works… is it okay?
                  thanx again

                  CoisesC 1 Reply Last reply Reply Quote 1
                  • CoisesC
                    Coises @Rockberto Manenti
                    last edited by

                    @Rockberto-Manenti said in regex to remove part of a line with variable words:

                    I made a mistake in giving the example but I didn’t think it would have an effect.
                    actually the text in the files is written like this:
                    title “the rover (led zeppelin cover)”
                    which should become:
                    title “the rover”

                    You didn’t make a mistake, I did. I assumed you were saying “this is the title” and using the quotation marks to delimit the text that was actually in the file. The only “mistake” you made was to miss the Literal Text Blocks section of FAQ: Formatting Forum Posts. FAQs are nice, but I doubt many people look there first.

                    @Rockberto-Manenti said in regex to remove part of a line with variable words:

                    I try with
                    \h*([^\r\n)]* cover)"$

                    and replace with "

                    now it works!
                    I don’t know if it’s right, but since it works… is it okay?

                    That’s what I was going to suggest next, so long as all the lines in your file are “title” lines as you described. (If there are other kind of lines as well, and you need to pick out just the ones that begin with “title,” it gets a little more complicated.)

                    Rockberto ManentiR 1 Reply Last reply Reply Quote 1
                    • Rockberto ManentiR
                      Rockberto Manenti @Coises
                      last edited by

                      @Coises
                      thanks for all the answers and suggestions, and sorry for my rudimentary English.
                      the text files are all .cue files for music flacs, and the lines where the phrase (Artist name cover) can be is always composed like this:
                      Title “song (artist name cover)”
                      of course song and artist name are variable but the word cover followed by the brackets and " are always at the end of the line.
                      Thanks for all the help… and I will try to read Literal Text Blocks when I finish editing the 3500 cue files!
                      Many thanks

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors