# How to retain text within quotes and discard the rest?

**URL:** https://community.mp3tag.de/t/how-to-retain-text-within-quotes-and-discard-the-rest/66975
**Category:** Support
**Created:** [December 28, 2024, 12:28am UTC](https://community.mp3tag.de/t/how-to-retain-text-within-quotes-and-discard-the-rest/66975 "2024-12-28T00:28:29Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![vicosphi](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/v/57b2e6/32.png) [@vicosphi](https://community.mp3tag.de/u/vicosphi)
#### Post date: [December 28, 2024, 12:28am UTC](https://community.mp3tag.de/t/how-to-retain-text-within-quotes-and-discard-the-rest/66975/1 "2024-12-28T00:28:29Z")

</div>

Hello,

I cannot appreciate enough how well written mp3tag is, so thank you to the devs!

I would like to edit the album title so that only the text within two double quotes is retained while discarding anything that is before and after the the double quotes. Example below:

**Current tag for Album field:** _Nexus sky (From "Distant Star Always") asteroid_  
**Expected result for Album field:** _Distant Star Always_

I am guessing I need to use Replace with regular expression? Any advise would be great. Thanks!

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [December 28, 2024, 7:26am UTC](https://community.mp3tag.de/t/how-to-retain-text-within-quotes-and-discard-the-rest/66975/2 "2024-12-28T07:26:23Z")

</div>

Try an action of the type "Replace with regular expression" for ALBUM  
Search pattern: `.*"(.*)".*`  
Replace with: $1

---

<div class="post-metadata">

### Author: ![vicosphi](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/v/57b2e6/32.png) [@vicosphi](https://community.mp3tag.de/u/vicosphi)
#### Post date: [December 28, 2024, 7:59am UTC](https://community.mp3tag.de/t/how-to-retain-text-within-quotes-and-discard-the-rest/66975/3 "2024-12-28T07:59:24Z")

</div>

Thanks for the reply! I tried your suggestion but got this error:  
`"The repeat operator "*" cannot start a regular expression.`

I did figure out the solution though 🤖

You create a new action "Replace with regular expression" and in regular expression, use  
`.*"([^"]+)".*`  
and replace with  
`$1`

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [December 28, 2024, 11:13am UTC](https://community.mp3tag.de/t/how-to-retain-text-within-quotes-and-discard-the-rest/66975/4 "2024-12-28T11:13:22Z")

</div>

Are you sure @vicosphi ?

The mentioned error

 ![image](https://community.mp3tag.de/uploads/default/original/3X/d/5/d599f78e310039f8dedad6e1f112b2f5d33c45a9.png)  
only occurs, if you missed the leading dot in the regular expression as  
incorrect: `*"(.*)".*`  
correct : `.*"(.*)".*`

In my own test @ohrenkino's regular expression works fine and

 ![image](https://community.mp3tag.de/uploads/default/original/3X/c/5/c58bc2a41c9310b1bd326e89596176a50e3312af.png)  
modifies the ALBUM content  
`Nexus sky (From "Distant Star Always") asteroid`  
to the new ALBUM content  
`Distant Star Always`

---

<div class="post-metadata">

### Author: ![vicosphi](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/v/57b2e6/32.png) [@vicosphi](https://community.mp3tag.de/u/vicosphi)
#### Post date: [December 28, 2024, 11:35am UTC](https://community.mp3tag.de/t/how-to-retain-text-within-quotes-and-discard-the-rest/66975/5 "2024-12-28T11:35:40Z")

</div>

> [@LyricsLover](#):
>
> ._"(._)".\*

Thanks again! That worked as well. I must have missed the period earlier. Appreciate the help!

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [December 28, 2024, 11:51am UTC](https://community.mp3tag.de/t/how-to-retain-text-within-quotes-and-discard-the-rest/66975/6 "2024-12-28T11:51:22Z")

</div>

> [@vicosphi](#):
>
> Thanks again! That worked as well.

To compare the two solutions:  
`.*"(.*)".*` means

 ![image](https://community.mp3tag.de/uploads/default/original/3X/d/c/dca8e5e06ee0c41a71bcc36a105cb66920dca298.png)

`.*"([^"]+)".*` means

 ![image](https://community.mp3tag.de/uploads/default/original/3X/1/5/15a17ba7d3152064049b6a6a88c0e4f2c1bd9fcd.png)  
IMHO this expression is more difficult to read and understand because of the grouping after the first `"` character.  
Instead of grouping _any character_ it is using _none of_ `"` until reaching the last `"` character.

The description _none of_ `"` can also be translated as  
_Match a single character not ^ present in the list. (The list `[]`contains `"`)_  
The + matches the previous token between one and unlimited times,

And BTW:  
Please be careful - with both expressions - if your current content in ALBUM contains 3 or more `"` characters.

---

<div class="post-metadata">

### Author: ![Casual\_Tea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/casual_tea/32/18886_2.png) [@Casual\_Tea](https://community.mp3tag.de/u/Casual_Tea)
#### Post date: [December 28, 2024, 1:33pm UTC](https://community.mp3tag.de/t/how-to-retain-text-within-quotes-and-discard-the-rest/66975/7 "2024-12-28T13:33:45Z")

</div>

> [@LyricsLover](#):
>
> Please be careful - with both expressions - if your current content in ALBUM contains 3 or more `"` characters.

I've dug into this a bit.  
If you always want the content of the first double quote pair, you can achieve that by making the first two asterisks non-greedy like this:

```auto
.*?"(.*?)".*

```

 ![grafik](https://community.mp3tag.de/uploads/default/original/3X/d/b/dbd6a70de83096aead887fc1354157a2d806032b.png)

Is the desired outcome the content of the last double quote pair, only make the asterisk in the capturing group non-greedy:

```auto
.*"(.*?)".*

```

 ![grafik](https://community.mp3tag.de/uploads/default/original/3X/8/8/88547f7bba86b9ea15d3eb1418da1f8f91ae6fe7.png)

And when you want to match a range in many double quotes, you can adapt the regex like this:

```auto
(?:.*?"){1}(.*?)".*

```

this will match the first pair

 ![grafik](https://community.mp3tag.de/uploads/default/original/3X/e/e/eebb2b829fd163149c3c14af185666a669fca0f1.png)

```auto
(?:.*?"){3}(.*?)".*

```

would match the second pair

 ![grafik](https://community.mp3tag.de/uploads/default/original/3X/0/9/0963a71997ee8fde4cad9f286d1ade201e8ee3bd.png)

```auto
(?:.*?"){5}(.*?)".*

```

would match the third pair and so on.

---

<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: [January 27, 2025, 1:34pm UTC](https://community.mp3tag.de/t/how-to-retain-text-within-quotes-and-discard-the-rest/66975/8 "2025-01-27T13:34:14Z")

</div>

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