# \[X\] Replace with Regular Expression

**URL:** https://community.mp3tag.de/t/x-replace-with-regular-expression/8140
**Category:** No Bugs
**Created:** [March 23, 2009, 8:59pm UTC](https://community.mp3tag.de/t/x-replace-with-regular-expression/8140 "2009-03-23T20:59:27Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![loveMusique](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/e19adc/32.png) [@loveMusique](https://community.mp3tag.de/u/loveMusique)
#### Post date: [March 23, 2009, 8:59pm UTC](https://community.mp3tag.de/t/x-replace-with-regular-expression/8140/1 "2009-03-23T20:59:27Z")

</div>

Hi Florian,

an example in German:  
Alt-5  
Feld:  
NETRADIOSTATION  
Regulärer Ausdruck:  
^.\*$  
Treffer ersetzen durch:  
Jamendo

Execution examples:

1. Field is empty — Result: Field is still empty.
2. Field is _not_ empty — Result: Field's content = "Jamendo"

IMHO this is a bug.

Ciao,  
Andreas

---

<div class="post-metadata">

### Author: ![Sebastian\_Mares](https://community.mp3tag.de/user_avatar/community.mp3tag.de/sebastian_mares/32/9285_2.png) [@Sebastian\_Mares](https://community.mp3tag.de/u/Sebastian_Mares)
#### Post date: [March 24, 2009, 4:27pm UTC](https://community.mp3tag.de/t/x-replace-with-regular-expression/8140/2 "2009-03-24T16:27:37Z")

</div>

Something else - why does using ".\*" as expression lead to the replacement string to be inserted twice?

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [March 26, 2009, 7:14pm UTC](https://community.mp3tag.de/t/x-replace-with-regular-expression/8140/3 "2009-03-26T19:14:47Z")

</div>

> [@loveMusique](#):
>
> Execution examples:
> 
> 1. Field is empty — Result: Field is still empty.
> 2. Field is _not_ empty — Result: Field's content = "Jamendo"

I'm using boost::regex as regular expression library which matches the null string when using the dot notation. My interpretation of this behaviour is, that a null string has neither a line begin ^ nor a line end $ so that the empty string isn't matched.

If the source string isn't empty, everything works as expected (also the null string isn't matched due to ^ and $).

> [@Sebastian Mares](#):
>
> Something else - why does using ".\*" as expression lead to the replacement string to be inserted twice?

This should now be very straightforward given the explanation above. Both the null string and the actual string are matched resulting in a duplication of the replace string.

Evil beasts, those regular expressions ![:rolleyes:](https://community.mp3tag.de/uploads/default/original/1X/3a79e8b0b7d169b30216785521d7c6f4f895c421.gif ":rolleyes:")

---

<div class="post-metadata">

### Author: ![loveMusique](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/e19adc/32.png) [@loveMusique](https://community.mp3tag.de/u/loveMusique)
#### Post date: [March 27, 2009, 10:27pm UTC](https://community.mp3tag.de/t/x-replace-with-regular-expression/8140/4 "2009-03-27T22:27:10Z")

</div>

Is your boost::regex different from Perl Regular Expressions?  
I am just curious...  
I am using Perl regexp since ages now - but as you said - still surprised from time to time...

LoL

---

<div class="post-metadata">

### Author: ![loveMusique](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/e19adc/32.png) [@loveMusique](https://community.mp3tag.de/u/loveMusique)
#### Post date: [March 27, 2009, 10:30pm UTC](https://community.mp3tag.de/t/x-replace-with-regular-expression/8140/5 "2009-03-27T22:30:46Z")

</div>

> [@Sebastian Mares](#):
>
> Something else - why does using ".\*" as expression lead to the replacement string to be inserted twice?

At least this won't happen in Perl regexp, because ".\*" always matches the whole string, "^" (begin) and "$" (end) included...

So much more experience with mp3tag::regexp is expected from me...  
😳

Ciao,  
Andreas

---

<div class="post-metadata">

### Author: ![loveMusique](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/e19adc/32.png) [@loveMusique](https://community.mp3tag.de/u/loveMusique)
#### Post date: [March 27, 2009, 10:33pm UTC](https://community.mp3tag.de/t/x-replace-with-regular-expression/8140/6 "2009-03-27T22:33:39Z")

</div>

> [@Florian](#):
>
> This should now be very straightforward given the explanation above. Both the null string and the actual string are matched resulting in a duplication of the replace string.

I am not happy with this explanation...

Ciao,  
Andreas

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [December 28, 2018, 2:25pm UTC](https://community.mp3tag.de/t/x-replace-with-regular-expression/8140/7 "2018-12-28T14:25:01Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
