Search code examples
regexreplacemp3

Regular Expression - Replace all except the file extension for file tagging


I'm working on cleaning up the tags of mp3s that contain the web links. I tried the regular expression that clears up the web-links

(\w+)*(\s|\-)(\w+\.(\w+))

with
$1

However, when I try using the same on the file, the extension is replaced. How do I make the extension here, .mp3 as an exception with the above regex?

I have tried using this but the replace takes more time


Solution

  • based on your examples, use this pattern

    \s-\s\S+(?=\.)
    

    and replace w/ nothing

    \s              # <whitespace character>
    -               # "-"
    \s              # <whitespace character>
    \S              # <not a whitespace character>
    +               # (one or more)(greedy)
    (?=             # Look-Ahead
      \.            # "."
    )               # End of Look-Ahead
    

    Demo