Question: 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](https://stackoverflow.com/questions/1141848/regex-to-match-url) but the replace takes more time

Answer: 
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](https://regex101.com/r/yW4aZ3/219)
If you replace by the first group only, sthi will only be the name of the file, extension not included.
Your regex do not actually catch the extension, it stops after the top level domain (.com) of the website.

You should use:

```
(\w+)(\s\-\s)(\w+\.\w+.\w+)(\.\w+)

```

![Regular expression visualization](https://www.debuggex.com/i/CiI2RgeKam20_gbQ.png)

[Debuggex Demo](https://www.debuggex.com/r/CiI2RgeKam20_gbQ)

and replace everything by groups 1 and 4. Reminds that usually the group 0 is containing the whole string matched by the regular expression.

More details, on the example "MySong - www.mysite.com.mp3:

```
    (\w+) // 1. will match "MySong", replace by ([\w\s]+) to match "My Song"
    (\s\-\s)  // 2. will match " - "
    (\w+\.\w+.\w+)  // 3. will match "www.mysite.com". You may want to let "www." be optional by replacing by "([\w+\.]?\w+.\w+)
    (\.\w+)  // 4. the '.mp3" extension

```