# Regular Expressions

**URL:** https://community.mp3tag.de/t/regular-expressions/521
**Category:** Howto
**Created:** [October 16, 2003, 4:47pm UTC](https://community.mp3tag.de/t/regular-expressions/521 "2003-10-16T16:47:29Z")
**Posts on this page:** 1
**Showing post:** 27

<div class="post-metadata">

### Author: ![incifinci](https://community.mp3tag.de/user_avatar/community.mp3tag.de/incifinci/32/6526_2.png) [@incifinci](https://community.mp3tag.de/u/incifinci)
#### Post date: [February 19, 2010, 8:24am UTC](https://community.mp3tag.de/t/regular-expressions/521/27 "2010-02-19T08:24:25Z")

</div>

### Switches first and last names

> [@areve](#):
>
> Another one, that switches first and last names (for instance, Jacques Brel will become Brel, Jacques):  
> Regular Expression: ^(.+)\s(.+)$  
> Replace with: $2, $1

Thank you!  
I developed it a little.

**Variant A**  
It will not change those artists, where the conversion already done (artist has comma).  
Example: Brel, Jacques William remains Brel, Jacques William

Action: regular expression  
Field: `ARTIST`  
Regular expression: `^([^,]+)\s([^,]+)$`  
Replace with: `$2, $1`

**Variant B**  
It handles multipled for WMP artists (in format "artist1/artist2/artist3"), possible nicknames at the end in square brackets and trims unnecessary white spaces.

Example:  
Elvis Presley /Brel, Jacques/ Gabriele Susanne Kerner [Nena]  
will  
Presley, Elvis/Brel, Jacques/Kerner, Gabriele Susanne [Nena]

Action group

1. action: regular expression (trim white spaces)  
Field: `ARTIST`  
Regular expression: `^\s+|\s+$`  
Replace with: (nothing)

2. action: regular expression (multiple white spaces replace to 1)  
Field: `ARTIST`  
Regular expression: `\s{2,}`  
Replace with: `" "` (whitout quotation marks)

3. action: replace (delete white space after opening bracket)  
Field: `ARTIST`  
Original: `"[ "` (whitout quotation marks)  
Replace with: `[`

4. action: replace (delete white space before closing bracket)  
Field: `ARTIST`  
Original: `" ]"` (whitout quotation marks)  
Replace with: `]`

5. action: split fields by separator (for the next actions)  
Field: `ARTIST`  
Separator: `/`

6. action: regular expression (switches names without nickname)  
Field: `ARTIST`  
Regular expression: `^([^,[]+)\s([^,[]+)$`  
Replace with: `$2, $1`

7. action: regular expression (switches names with nickname)  
Field: `ARTIST`  
Regular expression: `^([^,[]+)\s([^,[]+)\s(\[.+\])$`  
Replace with: `$2, $1 $3`

8. action: merge duplicate fields (...back)  
Field: `ARTIST`  
Separator: `/`

---

_[View the full topic](https://community.mp3tag.de/t/regular-expressions/521)._
