# \[X\] $regexp non-greedy fails

**URL:** https://community.mp3tag.de/t/x-regexp-non-greedy-fails/6262
**Category:** No Bugs
**Created:** [February 15, 2008, 2:40am UTC](https://community.mp3tag.de/t/x-regexp-non-greedy-fails/6262 "2008-02-15T02:40:04Z")
**Posts on this page:** 3
**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:40am UTC](https://community.mp3tag.de/t/x-regexp-non-greedy-fails/6262/1 "2008-02-15T02:40:04Z")

</div>

$regexp(axxxz,x.\*?z,) give a rather than axx as documented:

[https://docs.mp3tag.de/actions/replace-regexp](https://docs.mp3tag.de/actions/replace-regexp)  
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.

---

<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, 7:14pm UTC](https://community.mp3tag.de/t/x-regexp-non-greedy-fails/6262/2 "2008-02-15T19:14:22Z")

</div>

You have to keep in mind that regular expressions are evaluated from left to right.

Considering your example, the engine starts at **a**

1. a does not match against the pattern
2. x does match partially and gets consumed
3. x does match partially and gets consumed
4. x matches because it is followed by a z and both get consumed.

  
Not a bug in the regexp engine.

---

<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-non-greedy-fails/6262/3 "2018-12-28T14:22:24Z")

</div>

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