# Roman numbers in one single regular expression (regexp)

**URL:** https://community.mp3tag.de/t/roman-numbers-in-one-single-regular-expression-regexp/16343
**Category:** General Discussion
**Created:** [November 19, 2014, 12:20am UTC](https://community.mp3tag.de/t/roman-numbers-in-one-single-regular-expression-regexp/16343 "2014-11-19T00:20:44Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![vkostas](https://community.mp3tag.de/user_avatar/community.mp3tag.de/vkostas/32/227_2.png) [@vkostas](https://community.mp3tag.de/u/vkostas)
#### Post date: [November 19, 2014, 12:20am UTC](https://community.mp3tag.de/t/roman-numbers-in-one-single-regular-expression-regexp/16343/1 "2014-11-19T00:20:44Z")

</div>

Roman numbers from 1 to 3999.

1. e.g. 3746 = 3000 + 700 + 40 + 6 = MMM DCC XL VI = MMMDCCXLVI

2. Normalize regexp (1) 1000-3000: M{1,3} 100-900: C{1,3}|CD|D|DC{1,3}|CM 10-90: X{1,3}|XL|L|LX{1,3}|XC 1-9: I{1,3}|IV|V|VI{1,3}|IX
3. Normalize regexp (2) 1000-3000: M{1,3} 100-900: C{1,3}|D|DC{1,3}|CD|CM 10-90: X{1,3}|L|LX{1,3}|XL|XC 1-9: I{1,3}|V|VI{1,3}|IV|IX
4. Normalize regexp (3) 1000-3000: M{1,3} 100-900: C{1,3}|D|DC{1,3}|C[DM] 10-90: X{1,3}|L|LX{1,3}|X[LC] 1-9: I{1,3}|V|VI{1,3}|I[VX]
5. Normalize regexp (4) 1000-3000: M{1,3} 100-900: C[DM]|D|D?C{1,3} 10-90: X[LC]|L|L?X{1,3} 1-9: I[VX]|V|V?I{1,3}
6. Normalize regexp (5) 1000-3000: M{0,3} 100-900: C[DM]|D?C{0,3} 10-90: X[LC]|L?X{0,3} 1-9: I[VX]|V?I{0,3}
7. Normalize regexp (5a) an equivalent approach of (5) 1000-3000: M{0,3} 100-900: C[DM]|D?C?C?C? 10-90: X[LC]|L?X?X?X? 1-9: I[VX]|V?I?I?I?
8. Normalize regexp (6) **(M{0,3})**(C[DM]|D?C{0,3})**(X[LC]|L?X{0,3})**(I[VX]|V?I{0,3})
9. Normalize regexp (7) add word anchors \b**(M{0,3})**(C[DM]|D?C{0,3})**(X[LC]|L?X{0,3})**(I[VX]|V?I{0,3})\b
10. Normalize regexp (8) exclude zero-length match \b**(?=[MDCLXVI])**(M{0,3})**(C[DM]|D?C{0,3})****(X[LC]|L?X{0,3})**(I[VX]|V?I{0,3})\b
11. Final search pattern \b**(?=[MDCLXVI])**(M{0,3})**(C[DM]|D?C{0,3})**(X[LC]|L?X{0,3})**(I[VX]|V?I{0,3})**\b or \b**(?=[MDCLXVI])**(M?M?M?)**(C[DM]|D?C?C?C?)**(X[LC]|L?X?X?X?)**(I[VX]|V?I?I?I?)**\b

**Usage**  
Action type: Replace with regular expression.  
Field: (Title, etc)  
Regular expression: `\b(?=[MDCLXVI])(M{0,3})(C[DM]|D?C{0,3})(X[LC]|L?X{0,3})(I[VX]|V?I{0,3})\b`  
Replace with: `$upper($0)`

Regexp in Format Action type does nothing (is it a bug???? ![:rolleyes:](https://community.mp3tag.de/uploads/default/original/1X/3a79e8b0b7d169b30216785521d7c6f4f895c421.gif ":rolleyes:") ![:book:](https://community.mp3tag.de/uploads/default/original/1X/0036d5b68f6226c53f6c68abfd0a7b8096fd4505.gif ":book:") )

```
$regexp(%tag%,'\b(?=[MDCLXVI])(M{0,3})(C[DM]|D?C{0,3})(X[LC]|L?X{0,3})(I[VX]|V?I{0,3})\b',$upper($0))

```

[RomanNumbers.txt](https://community.mp3tag.de/uploads/default/original/2X/8/8cbecba03d182f1742fb657782a489f65ae0965c.txt) (59.5 KB)

---

_[View the full topic](https://community.mp3tag.de/t/roman-numbers-in-one-single-regular-expression-regexp/16343)._
