# \[X\] $regexp(X,.\*$,YY)

**URL:** https://community.mp3tag.de/t/x-regexp-x-yy/6261
**Category:** No Bugs
**Created:** [February 15, 2008, 2:31am UTC](https://community.mp3tag.de/t/x-regexp-x-yy/6261 "2008-02-15T02:31:29Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![chrisjj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@chrisjj](https://community.mp3tag.de/u/chrisjj)
#### Post date: [February 15, 2008, 2:31am UTC](https://community.mp3tag.de/t/x-regexp-x-yy/6261/1 "2008-02-15T02:31:29Z")

</div>

[EDITED:] ... returns YYYY rather than YY as documented.

---

<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: [February 15, 2008, 5:46pm UTC](https://community.mp3tag.de/t/x-regexp-x-yy/6261/2 "2008-02-15T17:46:00Z")

</div>

The regular expression from the topic return YYYY because .\* matches nothing **and** the X.

This is no bug and works as intended.

---

<div class="post-metadata">

### Author: ![chrisjj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@chrisjj](https://community.mp3tag.de/u/chrisjj)
#### Post date: [February 16, 2008, 5:41pm UTC](https://community.mp3tag.de/t/x-regexp-x-yy/6261/3 "2008-02-16T17:41:03Z")

</div>

> The regular expression from the topic return YYYY

(Agreed - my typo, sorry. Original report now corrected.)

> .\* matches nothing **and** the X.

Indeed, as proved by $regexp(X,(.\*)$,(\1)) -\> (X)()

I have used regexp in dozens of other tools and languages, and never seen a single wild card expression generate TWO SEPERATE replacement expressions.

> This is no bug

It is a failure to accord with the docs - \* is supposed to be greedy i.e. match everything in one hit.

Are the docs in error, then?

---

<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: [February 16, 2008, 6:46pm UTC](https://community.mp3tag.de/t/x-regexp-x-yy/6261/4 "2008-02-16T18:46:50Z")

</div>

> [@chrisjj](#):
>
> Are the docs in error, then?

No, I don't think so.

> [@](#):
>
> The dot character "." matches any single character.  
> [...]  
> "\*" repeated any number of times **including zero**

---

<div class="post-metadata">

### Author: ![chrisjj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@chrisjj](https://community.mp3tag.de/u/chrisjj)
#### Post date: [February 17, 2008, 12:38pm UTC](https://community.mp3tag.de/t/x-regexp-x-yy/6261/5 "2008-02-17T12:38:42Z")

</div>

> "\*" repeated any number of times including zero

That doesn't mean it isn't by default greedy. But

> Non-greedy repeats  
> Non-greedy repeats are possible by appending a '?' after the repeat;  
> a non-greedy repeat is one which will match the shortest possible string.

surely does.

What's your understanding Florian? Is \* (without ?) supposed to be greedy, or, not?

---

<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: [February 17, 2008, 4:17pm UTC](https://community.mp3tag.de/t/x-regexp-x-yy/6261/6 "2008-02-17T16:17:51Z")

</div>

> [@chrisjj](#):
>
> What's your understanding Florian? Is \* (without ?) supposed to be greedy, or, not?

Sure, that's why there is an extra specifier to turn of greedyness.

---

<div class="post-metadata">

### Author: ![chrisjj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@chrisjj](https://community.mp3tag.de/u/chrisjj)
#### Post date: [February 17, 2008, 4:57pm UTC](https://community.mp3tag.de/t/x-regexp-x-yy/6261/7 "2008-02-17T16:57:20Z")

</div>

> > Is \* (without ?) supposed to be greedy, or, not?  
> > Sure, that's why there is an extra specifier to turn of greedyness.

I take that to mean "Sure, it is supposed to be greedy".

Well, Florian, then it is not working properly.

When .\* is greedy, $regexp(X,._$,YY) gives YY because greedy ._ matches the entire input string, and that is replaced by a single occurence of the replacement string YY. This is indeed what I get on the other regexp implemetations I just tested.

But on Mp3tag, $regexp(X,.\*$,YY) gives YYYY.

> that's why there is an extra specifier to turn of greedyness.

Actually that doesn't work either, but let's deal with one issue at a time.

PS Here's a quote from [http://en.wikipedia.org/wiki/Regular\_expressions#Syntax](http://en.wikipedia.org/wiki/Regular_expressions#Syntax) which whilst not necessarily being a spec Mp3tag aims to comply with, does define what's generally meant by 'greedy':

. The standard quantifiers in regular expressions are greedy, meaning  
. they match as much as they can, only giving back as necessary to  
. match the remainder of the regex.

---

<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:22pm UTC](https://community.mp3tag.de/t/x-regexp-x-yy/6261/8 "2018-12-28T14:22:23Z")

</div>

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