# A little regex help with dots and spaces

**URL:** https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709
**Category:** Mac
**Created:** [December 3, 2024, 9:51am UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709 "2024-12-03T09:51:20Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Etz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/etz/32/7648_2.png) [@Etz](https://community.mp3tag.de/u/Etz)
#### Post date: [December 3, 2024, 9:51am UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/1 "2024-12-03T09:51:20Z")

</div>

Hey, yet again I seem to have a bit trouble with Mp3tag regex.

For example, field has something like this:

Dr. Test & A. B. C.

Now what I would like to do is remove spaces after dots, except for: dr. and vs. (and some others)

---

<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 3, 2024, 10:01am UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/2 "2024-12-03T10:01:14Z")

</div>

You need to define what exactly do you mean with "and some others".

Regular expression works best if you can exactly define what you want to keep or what you want to remove.

Please add some real examples and the current and the future syntax.

---

<div class="post-metadata">

### Author: ![Etz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/etz/32/7648_2.png) [@Etz](https://community.mp3tag.de/u/Etz)
#### Post date: [December 3, 2024, 10:16am UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/3 "2024-12-03T10:16:02Z")

</div>

In short, this is the regex, I am trying to use to match dot with space letters between single characters. According to regex101 it should work, but for some reason it does not seem to match in MP3tag

```auto
\b([a-z])(\.)\s

```

Action is currently for testing:

`XX`

Tried with action, $1$2 and $1$3 as well.

Example field was TITLE and contents were as follows (for testing)

Dr. Test A. V. C. blah blah

Basically, idea would be to remove space between single letters with dots like A. V. C. while keep everything else unchanged, like Dr. etc.  
What I am struggling with is to remove that space, in case it is there.

Using MacOS version, in case it matters.

---

<div class="post-metadata">

### Author: ![Etz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/etz/32/7648_2.png) [@Etz](https://community.mp3tag.de/u/Etz)
#### Post date: [December 3, 2024, 10:59am UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/4 "2024-12-03T10:59:18Z")

</div>

Also tried with different regex:

```auto
\b([a-z]\.\s)\b

```

It should match, for example `A. ` and action $trim($1) which did not seem to work either.

---

<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 3, 2024, 10:59am UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/5 "2024-12-03T10:59:34Z")

</div>

I tried  
`$regexp('Dr. Test & A. B. C.',(.*?)(\u\.)\s+(.*?),$1$2)`  
which led to  
`Dr. Test & A.B.C.`

---

<div class="post-metadata">

### Author: ![Etz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/etz/32/7648_2.png) [@Etz](https://community.mp3tag.de/u/Etz)
#### Post date: [December 3, 2024, 11:00am UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/6 "2024-12-03T11:00:57Z")

</div>

Yes, but this is not universal, I am afraid. 🙂

---

<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 3, 2024, 11:01am UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/7 "2024-12-03T11:01:47Z")

</div>

> [@Etz](#):
>
> Yes, but this is not universal

It works for the supplied example.  
You would have to replace the example string with the tag variable and try it.

---

<div class="post-metadata">

### Author: ![Etz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/etz/32/7648_2.png) [@Etz](https://community.mp3tag.de/u/Etz)
#### Post date: [December 3, 2024, 11:05am UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/8 "2024-12-03T11:05:14Z")

</div>

OK will try, but not sure how it translates to action atm.

---

<div class="post-metadata">

### Author: ![Etz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/etz/32/7648_2.png) [@Etz](https://community.mp3tag.de/u/Etz)
#### Post date: [December 3, 2024, 11:11am UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/9 "2024-12-03T11:11:04Z")

</div>

I think I may have discovered a bug @Florian

For example, when I spawn new action "Replace With Regular Expression" or duplicate existing one, it does not seem to work at all. No matter what I specify as Regex.  
But when I modified existing one, replacing Regex and Replace with new values it worked.

Otherwise, this seems to work:

Regex: `\b([a-z])\.\s(?!\w{2})\b`  
Replace: `$trim($1.)`

---

<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 3, 2024, 11:44am UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/10 "2024-12-03T11:44:19Z")

</div>

> [@Etz](#):
>
> it translates to action

Try an action of the type "Format tag field" for the corresponding field

---

<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 3, 2024, 11:45am UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/11 "2024-12-03T11:45:20Z")

</div>

> [@Etz](#):
>
> Replace: `$trim($1.)`

I do no thing that you can use scripting in the "replace" part - the action does not ask for a format string.

---

<div class="post-metadata">

### Author: ![Etz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/etz/32/7648_2.png) [@Etz](https://community.mp3tag.de/u/Etz)
#### Post date: [December 3, 2024, 12:18pm UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/12 "2024-12-03T12:18:40Z")

</div>

I have used such concept a lot in my actions and so far it has worked.

---

<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 3, 2024, 12:39pm UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/13 "2024-12-03T12:39:17Z")

</div>

> [@Etz](#):
>
> and so far it has worked

Please show such an example.

---

<div class="post-metadata">

### Author: ![Etz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/etz/32/7648_2.png) [@Etz](https://community.mp3tag.de/u/Etz)
#### Post date: [December 3, 2024, 1:07pm UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/14 "2024-12-03T13:07:06Z")

</div>

So I have to prove it that it does work now? 😃  
Fair enough...

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

All these actions do work, and replace supports string formatting:

> **[Scripting Functions – Mp3tag Documentation](https://docs.mp3tag.de/scripting/)**
>
> Documentation on Mp3tag's scripting functions. Mp3tag is the universal Tag Editor.

And string can be from regex match.

---

<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 3, 2024, 1:18pm UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/15 "2024-12-03T13:18:56Z")

</div>

Thank you.  
It works in different ways if you use the $regexp() or the "Replace with regular expression" function.

I just tested

> [@Etz](#):
>
> Regex: `\b([a-z])\.\s(?!\w{2})\b`

in Convert\>Tag-Tag  
and it does not return a hit but the original string.  
 ![grafik](https://community.mp3tag.de/uploads/default/original/3X/5/5/5566a01d66224101066179b2626dccf1da55b877.png)  
So what about the suggestion

> [@ohrenkino](#):
>
> $regexp('Dr. Test & A. B. C.',(._?)(\u.)\s+(._?),$1$2)

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

---

<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 3, 2024, 1:25pm UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/16 "2024-12-03T13:25:53Z")

</div>

> [@ohrenkino](#):
>
> I just tested in Convert\>Tag-Tag and it does not return a hit but the original string.

This is because, when using a scripting function in the replacement part of the `$regexp` function, the scripting function is evaluated _before_ the replacement occurs. This is due to the evaluation order of the scripting language.

The action Replace with Regular Expression supports scripting functions in the replacement part.

> [@ohrenkino](#):
>
> So what about the suggestion

This won't work on macOS, because the underlying [ICU regular expression engine](https://unicode-org.github.io/icu/userguide/strings/regexp.html) does not support `\u`.

In my experiments, the Java 8 flavour on regex101 is the closest match to simulate the behaviour of ICU.

---

<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 3, 2024, 1:29pm UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/17 "2024-12-03T13:29:03Z")

</div>

> [@Etz](#):
>
> I think I may have discovered a bug @Florian
> 
> For example, when I spawn new action "Replace With Regular Expression" or duplicate existing one, it does not seem to work at all. No matter what I specify as Regex.

I don't know how to reproduce this. Are you creating a new action inside an existing action group?

---

<div class="post-metadata">

### Author: ![Etz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/etz/32/7648_2.png) [@Etz](https://community.mp3tag.de/u/Etz)
#### Post date: [December 3, 2024, 1:32pm UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/18 "2024-12-03T13:32:13Z")

</div>

Duplicated existing one, swapped out contents...and did not work.  
Also replacement after -\> does not show in global list for such activity.  
Same happened when i spawned new one from scratch.  
But, when I took random existing activity and swapped out contents there, it worked immediately.

I will experiment a bit more later and let you know, how reproducible this is and maybe provide some proper bug report.

And yes, it is a new action inside existing group.  
Basically, I have one long list of actions in one group I run on newly purchased stuff, to "standardize" different fields to my liking.

---

<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 3, 2024, 1:42pm UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/19 "2024-12-03T13:42:33Z")

</div>

> [@Etz](#):
>
> I will experiment a bit more later and let you know, how reproducible this is and maybe provide some proper bug report.

It's working here, please provide (if possible) step-by-step instructions in case you can reproduce it.

---

<div class="post-metadata">

### Author: ![Etz](https://community.mp3tag.de/user_avatar/community.mp3tag.de/etz/32/7648_2.png) [@Etz](https://community.mp3tag.de/u/Etz)
#### Post date: [December 3, 2024, 1:56pm UTC](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/20 "2024-12-03T13:56:25Z")

</div>

Sure, will report back.

[Next page](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709.md?page=2)
