• Login
Community
  • Login

regex to remove part of a line with variable words

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
9 Posts 3 Posters 565 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.
  • R
    Rockberto Manenti
    last edited by Sep 21, 2024, 6:52 PM

    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

    C 1 Reply Last reply Sep 21, 2024, 7:08 PM Reply Quote 0
    • C
      Coises @Rockberto Manenti
      last edited by Coises Sep 21, 2024, 7:09 PM Sep 21, 2024, 7:08 PM

      @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.

      R 2 Replies Last reply Sep 21, 2024, 7:39 PM Reply Quote 1
      • R
        Rockberto Manenti @Coises
        last edited by Sep 21, 2024, 7:39 PM

        @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
        • R
          Rockberto Manenti @Coises
          last edited by Sep 21, 2024, 7:48 PM

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

          P 1 Reply Last reply Sep 21, 2024, 7:56 PM Reply Quote 0
          • P
            PeterJones @Rockberto Manenti
            last edited by Sep 21, 2024, 7:56 PM

            @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

            R 1 Reply Last reply Sep 21, 2024, 10:46 PM Reply Quote 0
            • R
              Rockberto Manenti @PeterJones
              last edited by Sep 21, 2024, 10:46 PM

              @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

              R 1 Reply Last reply Sep 21, 2024, 10:52 PM Reply Quote 1
              • R
                Rockberto Manenti @Rockberto Manenti
                last edited by Sep 21, 2024, 10:52 PM

                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

                C 1 Reply Last reply Sep 21, 2024, 11:01 PM Reply Quote 1
                • C
                  Coises @Rockberto Manenti
                  last edited by Sep 21, 2024, 11:01 PM

                  @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.)

                  R 1 Reply Last reply Sep 21, 2024, 11:24 PM Reply Quote 1
                  • R
                    Rockberto Manenti @Coises
                    last edited by Sep 21, 2024, 11:24 PM

                    @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
                    3 out of 9
                    • First post
                      3/9
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors