# Extracting matching string, else null

**URL:** https://community.mp3tag.de/t/extracting-matching-string-else-null/8738
**Category:** Support
**Created:** [August 8, 2009, 12:15pm UTC](https://community.mp3tag.de/t/extracting-matching-string-else-null/8738 "2009-08-08T12:15:07Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![chrisjj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@chrisjj](https://community.mp3tag.de/u/chrisjj)
#### Post date: [August 8, 2009, 12:15pm UTC](https://community.mp3tag.de/t/extracting-matching-string-else-null/8738/1 "2009-08-08T12:15:07Z")

</div>

What''s the most concise script expression that will return the match of regexp EEE in string SSS, else if there is no match, null?

Like **$if($regexpmatch(SSS,EEE),$regexp(SSS,EEE) , )** if $regexpmatch was available 🙂

Thanks.

---

<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 8, 2009, 3:29pm UTC](https://community.mp3tag.de/t/extracting-matching-string-else-null/8738/2 "2009-08-08T15:29:13Z")

</div>

If match then result is 1, if no match then result is 0.  
Example:  
$if($neql('20090808',$regexp('20090808','8',)),1,0)

DD.20090808.1929.CEST

---

<div class="post-metadata">

### Author: ![chrisjj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@chrisjj](https://community.mp3tag.de/u/chrisjj)
#### Post date: [August 9, 2009, 12:26pm UTC](https://community.mp3tag.de/t/extracting-matching-string-else-null/8738/3 "2009-08-09T12:26:36Z")

</div>

> $if($neql('20090808',$regexp('20090808','8',)),1,0)

To meet the requirement that way, it seems we would need

$if($neql(SSS,$regexp(SSS,EEE,RRR)),$regexp(SSS,EEE,RRR),)

Is there a solution that requires less duplication?

---

<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 9, 2009, 12:56pm UTC](https://community.mp3tag.de/t/extracting-matching-string-else-null/8738/4 "2009-08-09T12:56:05Z")

</div>

> [@chrisjj](#):
>
> ... it seems we would need  
> $if($neql(SSS,$regexp(SSS,EEE,RRR)),$regexp(SSS,EEE,RRR),) ...

I think it should be read ...  
**$if($neql(SSS,$regexp(SSS,EEE,)),$regexp(SSS,EEE,RRR),)**

DD.20090809.1655.CEST

---

<div class="post-metadata">

### Author: ![chrisjj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@chrisjj](https://community.mp3tag.de/u/chrisjj)
#### Post date: [August 9, 2009, 1:12pm UTC](https://community.mp3tag.de/t/extracting-matching-string-else-null/8738/5 "2009-08-09T13:12:36Z")

</div>

> I think it should be read ...  
> **$if($neql(SSS,$regexp(SSS,EEE,)),$regexp(SSS,EEE,RRR),)**

Aha, yes - thanks.

So is this "the most concise script expression", to do think? I would really like one without duplication, since SSS and sometimes EEE can be long expressions.

---

<div class="post-metadata">

### Author: ![chrisjj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@chrisjj](https://community.mp3tag.de/u/chrisjj)
#### Post date: [August 9, 2009, 1:15pm UTC](https://community.mp3tag.de/t/extracting-matching-string-else-null/8738/6 "2009-08-09T13:15:44Z")

</div>

> [@DetlevD](#):
>
> If match then result is 1, if no match then result is 0.  
> Example:  
> $if($neql('20090808',$regexp('20090808','8',)),1,0)

Note fails in the case

$if($neql(,$regexp(,'^$',)),1,0)

(returns 0) though this is not a problem to my application.

---

<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 9, 2009, 1:17pm UTC](https://community.mp3tag.de/t/extracting-matching-string-else-null/8738/7 "2009-08-09T13:17:13Z")

</div>

... and this can also happen ...  
**$if($neql(SSS,$regexp(SSS,EEE,)),$regexp(SSS,EEE,RRR),SSS)**  
... if someone wants to leave the original string untouched.

DD.20090809.1716.CEST

---

<div class="post-metadata">

### Author: ![chrisjj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@chrisjj](https://community.mp3tag.de/u/chrisjj)
#### Post date: [August 9, 2009, 3:42pm UTC](https://community.mp3tag.de/t/extracting-matching-string-else-null/8738/8 "2009-08-09T15:42:36Z")

</div>

> [@DetlevD](#):
>
> ... and this can also happen ...  
> **$if($neql(SSS,$regexp(SSS,EEE,)),$regexp(SSS,EEE,RRR),SSS)**  
> ... if someone wants to leave the original string untouched.

Surely $regexp itself is sufficient for that, since it leaves the original string untouched if no match.

---

<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 9, 2009, 4:28pm UTC](https://community.mp3tag.de/t/extracting-matching-string-else-null/8738/9 "2009-08-09T16:28:38Z")

</div>

> [@chrisjj](#):
>
> Surely $regexp itself is sufficient for that, since it leaves the original string untouched if no match.

The second regexp replace can only work when the first regexp catches a match, otherwise the if clause will return nothing, which would be able to distort the current field value, if this function starts from/with the value of the current field.

DD.20090809.2028.CEST

---

<div class="post-metadata">

### Author: ![chrisjj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@chrisjj](https://community.mp3tag.de/u/chrisjj)
#### Post date: [August 9, 2009, 6:44pm UTC](https://community.mp3tag.de/t/extracting-matching-string-else-null/8738/10 "2009-08-09T18:44:51Z")

</div>

> [@DetlevD](#):
>
> The second regexp replace can only work when the first regexp catches a match, otherwise the if clause will return nothing, which would be able to distort the current field value, if this function starts from/with the value of the current field.

Agreed, but what I am saying is surely

$if($neql(SSS,$regexp(SSS,EEE,)),$regexp(SSS,EEE,RRR),SSS)

and

$regexp(SSS,EEE,RRR)

give the same result.

---

<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 10, 2009, 1:38am UTC](https://community.mp3tag.de/t/extracting-matching-string-else-null/8738/11 "2009-08-10T01:38:07Z")

</div>

> [@chrisjj](#):
>
> Agreed, but what I am saying is surely  
> $if($neql(SSS,$regexp(SSS,EEE,)),$regexp(SSS,EEE,RRR),SSS) and $regexp(SSS,EEE,RRR) give the same result.

Yes, in this case there is no need to detect possible matching previously.

DD.20090910.0538.CEST

---

<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: [February 9, 2026, 12:21pm UTC](https://community.mp3tag.de/t/extracting-matching-string-else-null/8738/12 "2026-02-09T12:21:42Z")

</div>


