# $regexp nested inside another $regexp not working using captures

**URL:** <https://community.mp3tag.de/t/regexp-nested-inside-another-regexp-not-working-using-captures/40899>\
**Category:** Support\
**Created:** [February 22, 2018, 5:17pm UTC](https://community.mp3tag.de/t/regexp-nested-inside-another-regexp-not-working-using-captures/40899 "2018-02-22T17:17:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)\
**Post date:** [February 22, 2018, 5:17pm UTC](https://community.mp3tag.de/t/regexp-nested-inside-another-regexp-not-working-using-captures/40899/1 "2018-02-22T17:17:45Z")

</div>

`$trim($regexp('Genre 1 with Space, Genre 2 with Space, Genre 3 with Space','(,*)\s*([^\,]+[^,\s])','$1 [url=https://urlhere.com?taglist='$regexp($2,\s+,.)']'$2'[/url]'))`

Should output:  
`[url=https://urlhere.com?taglist=Genre.1.with.Space]Genre 1 with Space[/url], [url=https://urlhere.com?taglist=Genre.2.with.Space]Genre 2 with Space[/url], [url=https://urlhere.com?taglist=Genre.3.with Space]Genre 3 with Space[/url]`

Instead:  
`[url=https://urlhere.com?taglist=Genre 1 with Space]Genre 1 with Space[/url], [url=https://urlhere.com?taglist=Genre 2 with Space]Genre 2 with Space[/url], [url=https://urlhere.com?taglist=Genre 3 with Space]Genre 3 with Space[/url]`

Should the nested `$regexp($2,\s+,.)` not take care of replacing any `whitespaces` with `.`

A workaround for this would be appreciated.

---

<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 23, 2018, 7:51am UTC](https://community.mp3tag.de/t/regexp-nested-inside-another-regexp-not-working-using-captures/40899/2 "2018-02-23T07:51:11Z")

</div>

> [@stevehero](#):
>
> Should the nested $regexp($2,\s+,.) not take care of replacing any whitespaces with .

Not sure, whether you're posting this as a question or an observation 🙂

If it's a question, then the answer is no. Scripting functions are evaluated from the inmost to the outmost, so the when `$regexp($2,\s+,.)` is evaluated, `$2` doesn't have any content yet.

---

<div class="post-metadata">

**Author:** ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)\
**Post date:** [February 23, 2018, 12:50pm UTC](https://community.mp3tag.de/t/regexp-nested-inside-another-regexp-not-working-using-captures/40899/3 "2018-02-23T12:50:41Z")

</div>

> [@Florian](#):
>
> question or an observation

Both really.

> [@Florian](#):
>
> is evaluated, $2 doesn't have any content yet.

Technically it does when `$2` returns a string?

I'm confused.

`$2` is a returned string in my case, then `$regexp('This String',\s+String,)` works.

I know you say:

> [@Florian](#):
>
> Scripting functions are evaluated from the inmost to the outmost

🙋🏼‍♂️ So, no way to work around this? A new fn to exposed the capture as a string perhaps?

Maybe I could work backwards and replace any `\s` with `.` but I feel I may run into the same issue.

---

<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 23, 2018, 1:14pm UTC](https://community.mp3tag.de/t/regexp-nested-inside-another-regexp-not-working-using-captures/40899/4 "2018-02-23T13:14:05Z")

</div>

> [@stevehero](#):
>
> Technically it does when $2 returns a string?  
> (...)  
> $2 is a returned string in my case, then $regexp('This String',\s+String,) works.

Maybe I'm misunderstanding you here: `$2` is replaced by the contents of the 2nd match group only at the time when the outer `$regexp` is evaluated. So, sure — it "returns" a string, but at the time the inner `$regexp` is evaluated, it doesn't contain what you're assuming it to contain.

> [@stevehero](#):
>
> I'm confused.

Hopefully less confused now 😃

---

<div class="post-metadata">

**Author:** ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)\
**Post date:** [February 23, 2018, 1:30pm UTC](https://community.mp3tag.de/t/regexp-nested-inside-another-regexp-not-working-using-captures/40899/5 "2018-02-23T13:30:32Z")

</div>

> [@Florian](#):
>
> Hopefully less confused now

I'm not confused any more. Perhaps your opinion on a fn to convert captures as strings or something along that nature.

Possible future fn?

---

<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 24, 2018, 10:05am UTC](https://community.mp3tag.de/t/regexp-nested-inside-another-regexp-not-working-using-captures/40899/6 "2018-02-24T10:05:22Z")

</div>

No, most likely I won't add a dedicated function for that. It'd break the clear flow of data and make a already complicated feature even more complicated.

---

<div class="post-metadata">

**Author:** ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)\
**Post date:** [February 24, 2018, 1:43pm UTC](https://community.mp3tag.de/t/regexp-nested-inside-another-regexp-not-working-using-captures/40899/7 "2018-02-24T13:43:21Z")

</div>

No problem. There might be a way to change the string with lookarounds after the fact. Lookarounds aren't that straightforward but I'm sure there's a way.

---

<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 25, 2018, 9:46am UTC](https://community.mp3tag.de/t/regexp-nested-inside-another-regexp-not-working-using-captures/40899/8 "2018-02-25T09:46:57Z")

</div>

Another idea would be to replace the spaces in an outer regexp and move the rest to the inner one.

---

<div class="post-metadata">

**Author:** ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)\
**Post date:** [February 9, 2026, 12:27pm UTC](https://community.mp3tag.de/t/regexp-nested-inside-another-regexp-not-working-using-captures/40899/9 "2026-02-09T12:27:15Z")

</div>


