# Two Regex Questions

**URL:** https://community.mp3tag.de/t/two-regex-questions/15899
**Category:** General Discussion
**Created:** [July 11, 2014, 7:33am UTC](https://community.mp3tag.de/t/two-regex-questions/15899 "2014-07-11T07:33:25Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![marcusj0015](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@marcusj0015](https://community.mp3tag.de/u/marcusj0015)
#### Post date: [July 11, 2014, 7:33am UTC](https://community.mp3tag.de/t/two-regex-questions/15899/1 "2014-07-11T07:33:25Z")

</div>

I have two questions.

Question 1: regex pattern that will replace multiple consecutive spaces with a single space

Question 2: regex that will ignore parentheses but NOT ignore everything inside the parentheses.

so it would see: Lil Wayne (feat. Kanye West), and see this: Lil Wayne feat. Kanye West, how do I do this? WITHOUT removing the parentheses (because some songs have stuff like Remix in parentheses, and I want that to stay, I ONLY want it to remove the parentheses if feat is in between the parentheses)

also, do you guys know of a good book about the regex system you use so I can learn this myself?

---

<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: [July 11, 2014, 10:35am UTC](https://community.mp3tag.de/t/two-regex-questions/15899/2 "2014-07-11T10:35:20Z")

</div>

> [@marcusj0015](#):
>
> I have two questions.
> 
> Question 1: regex pattern ...
> 
> Question 2: regex ...lf?

you do not need regex for that as you replace text constants.  
One is "(feat" replace with "feat".  
and the other is " " (2 blanks) with " " (1 blank)

---

<div class="post-metadata">

### Author: ![JJ\_Johnson](https://community.mp3tag.de/user_avatar/community.mp3tag.de/jj_johnson/32/67_2.png) [@JJ\_Johnson](https://community.mp3tag.de/u/JJ_Johnson)
#### Post date: [July 11, 2014, 2:20pm UTC](https://community.mp3tag.de/t/two-regex-questions/15899/3 "2014-07-11T14:20:30Z")

</div>

> [@marcusj0015](#):
>
> Question 1: regex pattern that will replace multiple consecutive spaces with a single space

This action will replace multiple spaces with a single space and also remove any leading or trailing spaces.

_Action type:_ **Format value**  
_Field:_ **ARTIST**  
_Format string:_ **$regexp($trim(%artist%),\s+, ,1)**

(Make sure you place a single space between the two commas.)

> [@](#):
>
> Question 2: regex that will ignore parentheses but NOT ignore everything inside the parentheses.
> 
> so it would see: Lil Wayne (feat. Kanye West), and see this: Lil Wayne feat. Kanye West, how do I do this? WITHOUT removing the parentheses (because some songs have stuff like Remix in parentheses, and I want that to stay, I ONLY want it to remove the parentheses if feat is in between the parentheses)

This action should do it. The text within the parentheses has to match"(feat. xxxxx)" exactly , including the period. It could be made more flexible if you like: for example to also match "feat" without the period, or to also match "featuring".

_Action type:_ **Replace with regular expression**  
_Field:_ **TITLE**  
_Regular expression:_ **(._)((feat. [^)]_))(.\*)**  
_Replace matches with:_ **$1$2$3**  
 _case-sensitive comparison_

> [@](#):
>
> also, do you guys know of a good book about the regex system you use so I can learn this myself?

That would probably be [Introducing Regular Expressions](http://shop.oreilly.com/product/0636920012337.do). Here it is [on Amazon](http://www.amazon.com/Introducing-Regular-Expressions-Michael-Fitzgerald/dp/1449392687).

There is also [Mastering Regular Expressions](http://shop.oreilly.com/product/9780596528126.do), which is often considered the regex Bible, but it's more advanced and it's pricey. [On Amazon](http://www.amazon.com/Mastering-Regular-Expressions-%20Jeffrey-Friedl/dp/0596528124).

The web site [Regular-Expressions.info](http://www.regular-expressions.info/) is very good for learning. I'd recommend starting there.

---

<div class="post-metadata">

### Author: ![marcusj0015](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@marcusj0015](https://community.mp3tag.de/u/marcusj0015)
#### Post date: [July 12, 2014, 5:34am UTC](https://community.mp3tag.de/t/two-regex-questions/15899/4 "2014-07-12T05:34:53Z")

</div>

Is there any way the white space one can be made available for all fields without duplicating the action a million times?

---

<div class="post-metadata">

### Author: ![JJ\_Johnson](https://community.mp3tag.de/user_avatar/community.mp3tag.de/jj_johnson/32/67_2.png) [@JJ\_Johnson](https://community.mp3tag.de/u/JJ_Johnson)
#### Post date: [July 12, 2014, 6:03am UTC](https://community.mp3tag.de/t/two-regex-questions/15899/5 "2014-07-12T06:03:34Z")

</div>

Use the field **\_ALL**

---

<div class="post-metadata">

### Author: ![marcusj0015](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@marcusj0015](https://community.mp3tag.de/u/marcusj0015)
#### Post date: [July 12, 2014, 6:58am UTC](https://community.mp3tag.de/t/two-regex-questions/15899/6 "2014-07-12T06:58:11Z")

</div>

oh my god why didn't I think of that?! I tried using \_TAG and it didn't work!

---

<div class="post-metadata">

### Author: ![Nature](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/n/a587f6/32.png) [@Nature](https://community.mp3tag.de/u/Nature)
#### Post date: [July 31, 2014, 9:18am UTC](https://community.mp3tag.de/t/two-regex-questions/15899/7 "2014-07-31T09:18:14Z")

</div>

For online sources about RegEx (Regular Expressions), I would recommend two:

1. This is the best source for RegEx that I know of:  
[https://docs.python.org/2/library/re.html](https://docs.python.org/2/library/re.html)

I've learned almost everything about Regular Expressions with this single webpage.  
It's very clear and contains examples about almost every possible scenario.

1. However, Mp3Tag help system also has a good beginner's manual with all the important features of RegEx (perhaps all you need now). Look here, at the bottom:  
[https://docs.mp3tag.de/actions](https://docs.mp3tag.de/actions)

---

<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: [July 31, 2014, 9:48am UTC](https://community.mp3tag.de/t/two-regex-questions/15899/8 "2014-07-31T09:48:59Z")

</div>

> [@Nature](#):
>
> For online sources about RegEx (Regular Expressions), I would recommend ...

Do not forget to learn from there ...  
[/t/521/1](https://community.mp3tag.de/t/521/1)

... especially there is a nice walk through ....  
[Regular Expressions](https://community.mp3tag.de/t/521/36)

DD.20140731.1349.CEST

---

<div class="post-metadata">

### Author: ![lowandslow](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/aca169/32.png) [@lowandslow](https://community.mp3tag.de/u/lowandslow)
#### Post date: [August 5, 2014, 9:54pm UTC](https://community.mp3tag.de/t/two-regex-questions/15899/9 "2014-08-05T21:54:14Z")

</div>

> [@marcusj0015](#):
>
> also, do you guys know of a good book about the regex system you use so I can learn this myself?

This is the best way to learn! --\> [Regex Crossword](http://regexcrossword.com/)

It is interactive and the crosswords are progressive. It took me about two weeks to complete all nine of the crosswords, and I didn't know any regex before. It's a fun way to learn. Highly recommend it.

Here are some resources I used:

- [http://www.regexr.com/](http://www.regexr.com/)
- [http://regex101.com](http://regex101.com)
- [http://ole.michelsen.dk/tools/regex.htm](http://ole.michelsen.dk/tools/regex.htm)l
- [http://www.regular-expressions.info](http://www.regular-expressions.info)

---

<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: [August 6, 2014, 4:56am UTC](https://community.mp3tag.de/t/two-regex-questions/15899/10 "2014-08-06T04:56:22Z")

</div>

> [@marcusj0015](#):
>
> ... I tried using \_TAG and it didn't work!

Because ...

\_ALL = \_TAG + \_FILENAME

... it does work also on \_TAG alone.

DD.20140806.0856.CEST
