• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 468
  • Last Modified:

perl regex help

3 Inches Of Blood - Fire Up The Blades (2007) [v1]
Abuse - A Sunday Morning Killing Spree (1999) [192]
Agressor - 01. Neverending Destiny (1990) [ogg224]

I need a perl regex to replace any character sequence or digit inside the [] at the end of the line.

I'm trying to learn perl regex but struggling to do anything other than really basic stuff.
The result of the regex should do something like below

3 Inches Of Blood - Fire Up The Blades (2007) [v0]
Abuse - A Sunday Morning Killing Spree (1999) [v0]
Agressor - 01. Neverending Destiny (1990) [v0]

It must only replace at the end of the line too. There could be examples of square brackets in the title. And the replace variable can be any length and must replace whatever is in the [ ] ...not just the same length as the replacing variable.

Thanks in advance
  • 2
  • 2
1 Solution
NorthReptileAuthor Commented:
Thanks a lot.

What does the /gm do at the end?

One further question, if you don't mind.

In same cases if the word ogg is in the  [ ] followed by a number could i exclude this in the same regex?


blah blah [ogg256]
blah again [ogg224]

both would be untouched by the replacing.
NorthReptileAuthor Commented:
I'm trying to break down what you did to understand it further.


This also works with out [.*?]. Can you tell me what the difference is?

In one of the guides on regex it has the same definition for * and ?

*      # Zero or more of the last character
?      # Zero or one of the last character



does not work.
\[.*\] matches the longest sequence
\[.*?\] matches the shortest sequence
but since they both must match at the end $
it doesn't make a difference in this case, and I should have said
so that it only matches the last [] when there are more than one
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now