# Question/Problem regarding Regular Expression Capturing GROUPS: "$regexp(x,e,r,c)" vs "Replace with regular expression" (ONLY available via .MTA/Quick Action)

**URL:** https://community.mp3tag.de/t/question-problem-regarding-regular-expression-capturing-groups-regexp-x-e-r-c-vs-replace-with-regular-expression-only-available-via-mta-quick-action/68931
**Category:** Support
**Created:** [June 24, 2025, 12:34am UTC](https://community.mp3tag.de/t/question-problem-regarding-regular-expression-capturing-groups-regexp-x-e-r-c-vs-replace-with-regular-expression-only-available-via-mta-quick-action/68931 "2025-06-24T00:34:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![wneclass2018](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/w/cdc98d/32.png) [@wneclass2018](https://community.mp3tag.de/u/wneclass2018)
#### Post date: [June 24, 2025, 12:34am UTC](https://community.mp3tag.de/t/question-problem-regarding-regular-expression-capturing-groups-regexp-x-e-r-c-vs-replace-with-regular-expression-only-available-via-mta-quick-action/68931/1 "2025-06-24T00:34:01Z")

</div>

Concerning group capture (i.e., "add `12` to `$1` PM"), the two strings BELOW 100% **WORKS** for " **Replace with regular expression**" (ONLY available via .MTA/Quick Action):

> Field: DATE\_TIME\_BACKUP  
> Regular expression: (?\<![\d])(0?[1-9]|1[0-1])(?![\d])(?=(?:[:]\d{1,2}){2}[\W\_]\*PM)  
> Replace matches with: $add($1,12)
> 
> Field: DATE\_TIME\_BACKUP  
> Regular expression: (?\<![\d])(0?[1-9]|1[0-2])((?:[:]\d{1,2}){2}[\W\_]\*)([AP]M)(?![\d])  
> Replace matches with: $if($eql($1,12),$if($eql($3,am),$sub($1,12),$1),$if($eql($3,am),$1,$add($1,12)))$2$3

However, the two strings, BELOW, 100% **FAILS** when using "**$regexp(x,e,r,c)**", regarding group capture (i.e., "add `12` to `$1` PM"):

> $regexp(%date\_time\_backup%,'(?\<![\d])(0?[1-9]|1[0-1])(?![\d])(?=(?:[:]\d{1,2}){2}[\W\_]\*PM)',$add($1,12),1)
> 
> $regexp(%date\_time\_backup%,'(?\<![\d])(0?[1-9]|1[0-2])((?:[:]\d{1,2}){2}[\W\_]\*)([AP]M)(?![\d])',$if($eql($1,12),$if($eql($3,am),$sub($1,12),$1),$if($eql($3,am),$1,$add($1,12)))$2$3,1)

I was wondering, when searching `(?<![\d])(0?[1-9]|1[0-1])(?![\d])(?=(?:[:]\d{1,2}){2}[\W_]*PM)`, why does the group replacement, `$add($1,12)`, **FAIL** when I use **$regexp(x,e,r,c)**, but **100% WORKS** when I use **Replace with regular expression**? Moreover, if I use **Replace with regular expression** and search for `(?<![\d])(0?[1-9]|1[0-2])((?:[:]\d{1,2}){2}[\W_]*)([AP]M)(?![\d])`, the **Replace with regular expression** allows me to replace with "`$if($eql($1,12),$if($eql($3,am),$sub($1,12),$1),$if($eql($3,am),$1,$add($1,12)))$2$3`". Basically, concerning the use of **$regexp(x,e,r,c)**, my problem is why does the string, `$regexp(%date_time_backup%,'(?<![\d])(0?[1-9]|1[0-1])(?![\d])(?=(?:[:]\d{1,2}){2}[\W_]*PM)',$add($1,12),1)` **FAIL** to add `12` to `$1` PM? Nevertheless, my only alternative was to use my 2022 string, `$regexp(%date_time_backup%,'(?<![\d])(0?[1-9]|1[0-1])(?![\d])(?=(?:[:]\d{1,2}){2}[\W_]*PM)',$add($regexp(%date_time_backup%,'^.*(?<![\d])(0?[1-9]|1[0-1]):(\d{1,2}:\d{1,2})(?![\d]).*$',$1),12),1)`, for it to **add** 12 to PM"?

Therefore, I was wondering how can I make the scripting function _**$regexp(x,e,r,c)**_ work the SAME way as **Replace with regular expression**? Is there something that I am missing on my end in order to replace with capturing groups with another scripting function, such as `$add(x,y)` ~ `$add($1,12)` when using _**$regexp(x,e,r,c)**_?

---

<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: [June 24, 2025, 5:27am UTC](https://community.mp3tag.de/t/question-problem-regarding-regular-expression-capturing-groups-regexp-x-e-r-c-vs-replace-with-regular-expression-only-available-via-mta-quick-action/68931/2 "2025-06-24T05:27:46Z")

</div>

See here:

> [@A little regex help with dots and spaces](https://community.mp3tag.de/t/a-little-regex-help-with-dots-and-spaces/66709/16):
>
> 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. 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…

---

<div class="post-metadata">

### Author: ![wneclass2018](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/w/cdc98d/32.png) [@wneclass2018](https://community.mp3tag.de/u/wneclass2018)
#### Post date: [June 24, 2025, 10:21pm UTC](https://community.mp3tag.de/t/question-problem-regarding-regular-expression-capturing-groups-regexp-x-e-r-c-vs-replace-with-regular-expression-only-available-via-mta-quick-action/68931/3 "2025-06-24T22:21:06Z")

</div>

Hmmm interesting. Thank you. Moreover, I wish, in the near future, that issue could be fixed because you can use **$regexp(x,e,r,c)** anywhere in Mp3Tag (i.e., .MTA, .MTE, columns.ini, tools.ini, Actions {Quick}, etc), while you can ONLY use **Replace with regular expression** in .MTA and Actions (Quick). Nonetheless, thanks again for the quick response.

---

<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: [June 25, 2025, 6:56am UTC](https://community.mp3tag.de/t/question-problem-regarding-regular-expression-capturing-groups-regexp-x-e-r-c-vs-replace-with-regular-expression-only-available-via-mta-quick-action/68931/4 "2025-06-25T06:56:06Z")

</div>

I am not sure what should be fixed - AFAI see it, the scripting statement only has to be set according to the underlying function, which means that you first have to extract the string (in this case a number) and then use that for further treatment.  
It does not work to manipulate the result string directly - which you know by now.  
Your original string followed that approach. So you will reach your goal in the end.

---

<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: [July 25, 2025, 6:56am UTC](https://community.mp3tag.de/t/question-problem-regarding-regular-expression-capturing-groups-regexp-x-e-r-c-vs-replace-with-regular-expression-only-available-via-mta-quick-action/68931/5 "2025-07-25T06:56:07Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
