# How to remove apostrophes from search query w/ $regexp?

**URL:** <https://community.mp3tag.de/t/how-to-remove-apostrophes-from-search-query-w-regexp/17818>\
**Category:** Support\
**Created:** [April 4, 2016, 2:22pm UTC](https://community.mp3tag.de/t/how-to-remove-apostrophes-from-search-query-w-regexp/17818 "2016-04-04T14:22:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ms6676749](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@ms6676749](https://community.mp3tag.de/u/ms6676749)\
**Post date:** [April 4, 2016, 2:22pm UTC](https://community.mp3tag.de/t/how-to-remove-apostrophes-from-search-query-w-regexp/17818/1 "2016-04-04T14:22:20Z")

</div>

Discogs throws up 401 errors with queries containing apostrophes. So, I try to strip apostrophes (and other offending characters) from my queries. Everything else but apostrophes are stripped. Trying to include an escaped apostrophe (,) in the bolded array below doesn't work and including an apostrophe doesn't work due to the bordering bracket(?) apostrophes. Any other ideas?

[SearchBy]=$if($eql(%albumartist%,'Various Artists'),'Various'&release\_title=$regexp($regexp(%album%,'\s+[.+]$',,1),'**[-_.,+!(){}[]^"~\*?:\\]_**',),$regexp($regexp(%albumartist%,'\s+[.+]$',,1),'[-.+!(){}[]^"~_?:\\]',)&release\_title=$regexp($regexp(%album%,'\s+[.+]$',,1),'**[-\_.+!(){}[]^"~**_?,:\\]',))

---

<div class="post-metadata">

**Author:** ![ryerman](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ryerman/32/5285_2.png) [@ryerman](https://community.mp3tag.de/u/ryerman)\
**Post date:** [April 4, 2016, 4:07pm UTC](https://community.mp3tag.de/t/how-to-remove-apostrophes-from-search-query-w-regexp/17818/2 "2016-04-04T16:07:05Z")

</div>

[https://docs.mp3tag.de/scripting](https://docs.mp3tag.de/scripting)

Try escaping ' with ''. (that's 2 single apostrophes)

---

<div class="post-metadata">

**Author:** ![ms6676749](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@ms6676749](https://community.mp3tag.de/u/ms6676749)\
**Post date:** [April 4, 2016, 4:35pm UTC](https://community.mp3tag.de/t/how-to-remove-apostrophes-from-search-query-w-regexp/17818/3 "2016-04-04T16:35:47Z")

</div>

I tried it already (I should've included that in my OP), but while I avoid [SYNTAX ERROR] it doesn't strip out the apostrophes.

```
&release_title=$regexp($regexp(%album%,'\s+\[.+\]$',,1),'[-_''.+!(){}\[\]^"~*?,:\\\\]',))

```

Likewise, the same output occurs in the following:

```
&release_title=$regexp($regexp($regexp(%album%,'\s+\[.+\]$',,1),'[-_.+!(){}\[\]^"~*?,:\\\\]',),'',)

```

input: 60's Beat Girls Collection, Vol. 1: Japanese Pop Cuties in Swingin' 60's  
output: 60's Beat Girls Collection Vol 1 Japanese Pop Cuties in Swingin' 60's

---

<div class="post-metadata">

**Author:** ![ryerman](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ryerman/32/5285_2.png) [@ryerman](https://community.mp3tag.de/u/ryerman)\
**Post date:** [April 4, 2016, 5:18pm UTC](https://community.mp3tag.de/t/how-to-remove-apostrophes-from-search-query-w-regexp/17818/4 "2016-04-04T17:18:16Z")

</div>

I tested your code in the tag panel and it seems to work as you require. See attached.

 ![](https://community.mp3tag.de/uploads/default/original/2X/5/58d6dd9f31d401237cf234ed4a8341ed9a2d5d08.PNG)

---

<div class="post-metadata">

**Author:** ![ms6676749](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@ms6676749](https://community.mp3tag.de/u/ms6676749)\
**Post date:** [April 4, 2016, 6:09pm UTC](https://community.mp3tag.de/t/how-to-remove-apostrophes-from-search-query-w-regexp/17818/5 "2016-04-04T18:09:06Z")

</div>

> [@ryerman](#):
>
> I tested your code in the tag panel and it seems to work as you require. See attached.

I intended to use the code in a websource discogs (see [SearchBY] in OP), hence my attempt to workaround Discog's contempt (401 errors) for nearly all punctuation marks in the search query. I never tried it in an action script.

For example (album: Leaders Of The Pack: The Very Best Of The 60's Girls), running my discogs websource, the current code yields the following query:

[https://api.discogs.com/database/search?typ...e\_title=Leaders](https://api.discogs.com/database/search?type=release&per_page=100&artist=Various&release=Various&release_title=Leaders) Of The Pack The Very Best Of The 60's Girls

As you can see, all of the punctuation marks are stripped except the apostrophe. When running this query, discogs throws up a 401 message.

Pone's discogs script strips out ('s), but it leaves trailing apostrophes around (i.e. Swingin')

The following query works (w/o the apostrophe), but my code is unable to strip it out.

[https://api.discogs.com/database/search?typ...e\_title=Leaders](https://api.discogs.com/database/search?type=release&per_page=100&artist=Various&release=Various&release_title=Leaders) Of The Pack The Very Best Of The 60s Girls

EDIT: Even a simple removal of any non-alphanumeric characters (/[^a-zA-Z0-9]/g) still leaves apostrophes behind in the ParserScriptIndex. Something is very wrong here.

[https://regex101.com/r/pI8xA4/3](https://regex101.com/r/pI8xA4/3)

---

<div class="post-metadata">

**Author:** ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)\
**Post date:** [April 4, 2016, 6:45pm UTC](https://community.mp3tag.de/t/how-to-remove-apostrophes-from-search-query-w-regexp/17818/6 "2016-04-04T18:45:12Z")

</div>

> [@ms6676749](#):
>
> Discogs throws up 401 errors with queries containing apostrophes. So, I try to strip apostrophes (and other offending characters) from my queries. Everything else but apostrophes are stripped. ...

You may try this formatstring ...

**$regexp(%ALBUM%,'(\s+\[.+\]$)|\x27|'$regexp('-\_.+!(){}[]^$~\*?,:\','.','|\\\\$0'),,1)**

... or ...

**$regexp(%ALBUM%,'(\s+\[.+\]$)|\x27|[^\w\s]',,1)**

DD.20160404.2306.CEST

---

<div class="post-metadata">

**Author:** ![ryerman](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ryerman/32/5285_2.png) [@ryerman](https://community.mp3tag.de/u/ryerman)\
**Post date:** [April 4, 2016, 7:13pm UTC](https://community.mp3tag.de/t/how-to-remove-apostrophes-from-search-query-w-regexp/17818/7 "2016-04-04T19:13:08Z")

</div>

> [@ms6676749](#):
>
> I intended to use the code in a websource discogs (see [SearchBY] in OP), hence my attempt to workaround Discog's contempt (401 errors) for nearly all punctuation marks in the search query. I never tried it in an action script.
> 
> For example (album: Leaders Of The Pack: The Very Best Of The 60's Girls), running my discogs websource, the current code yields the following query:
> 
> [https://api.discogs.com/database/search?typ...e\_title=Leaders](https://api.discogs.com/database/search?type=release&per_page=100&artist=Various&release=Various&release_title=Leaders) Of The Pack The Very Best Of The 60's Girls

When I use the links to your examples I get this:  
{"message": "You must authenticate to access this resource."}

I guess that is because I'm not authenticated on your account.

But using the default SRC script (discogs.src), I just searched for this: deliverin' the good's  
There was 11 results.  
So it seems it's possible to search with apostrophes in the string.

Then I modified the script with your regex replacements and tried again and got the same 11 search results.  
Maybe it's something other than apostrophes that cause the problem.

So then I tried your original input example.  
That produced the 401 error.  
But when I tried the same string without the dot after "Vol" I got the "Sorry, no entries..." message.  
I guess that means something.

Have fun sorting it out!

Maybe a real expert will help. I'll keep experimenting, but I don't know much about source scripts.

---

<div class="post-metadata">

**Author:** ![ms6676749](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@ms6676749](https://community.mp3tag.de/u/ms6676749)\
**Post date:** [April 4, 2016, 8:04pm UTC](https://community.mp3tag.de/t/how-to-remove-apostrophes-from-search-query-w-regexp/17818/8 "2016-04-04T20:04:46Z")

</div>

> [@ryerman](#):
>
> When I use the links to your examples I get this:  
> {"message": "You must authenticate to access this resource."}
> 
> I guess that is because I'm not authenticated on your account.
> 
> But using the default SRC script (discogs.src), I just searched for this: deliverin' the good's  
> There was 11 results.  
> So it seems it's possible to search with apostrophes in the string.
> 
> Then I modified the script with your regex replacements and tried again and got the same 11 search results.  
> Maybe it's something other than apostrophes that cause the problem.
> 
> Maybe a real expert will help. I'll keep experimenting, but I don't know much about source scripts.

Okay, I am a dumbass. I now realize that bypassed my %albumartist% $if statement when trying out my code. All of this time I triggered that $if statement when testing the code out on compilation albums (albumartist=Various Artists). The escape character for apostrophes worked as expected, but I have to admit that DetlevD's [regex](https://community.mp3tag.de/t/17818/6) looks a lot cleaner.

Anyways, thanks guys for the help. I'm no expert myself. I just read some docs, looked at some old sources and created a few unavailable ones for personal use.

Ryerman you are correct in saying that apostrophes are accepted with the regular discogs.src. I opened up my browser and tried the search string from Pone's script and it worked:  
[https://api.discogs.com/database/search?type=release&per\_page=100&artist=Various&release\_title=Leaders](https://api.discogs.com/database/search?type=release&per_page=100&artist=Various&release_title=Leaders) Of The Pack: The Very Best Of The 60's Girls&token=(my token 'without the parenthesis')

---

<div class="post-metadata">

**Author:** ![ryerman](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ryerman/32/5285_2.png) [@ryerman](https://community.mp3tag.de/u/ryerman)\
**Post date:** [April 5, 2016, 12:11am UTC](https://community.mp3tag.de/t/how-to-remove-apostrophes-from-search-query-w-regexp/17818/9 "2016-04-05T00:11:46Z")

</div>

You're never a dumbass when you make an honest mistake, but then find and correct it.  
At least you had the decency to come back and explain (not that I understand 😉 ).  
Not everybody does that.

DetlevD is one of the resident Regex experts around here. I'm not.

---

<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:26pm UTC](https://community.mp3tag.de/t/how-to-remove-apostrophes-from-search-query-w-regexp/17818/10 "2026-02-09T12:26:11Z")

</div>

Closed on February 9, 2026, 12:26pm UTC


