regex to remove part of a line with variable words
-
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 -
@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.
-
@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…
-
@Coises
it doesn’t work, it didn’t find any results.
I selected regular expression -
@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
-
@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 -
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 -
@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.)
-
@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