# $Regexp returns full field on no match instead of blank/null

**URL:** <https://community.mp3tag.de/t/regexp-returns-full-field-on-no-match-instead-of-blank-null/61359>\
**Category:** Support\
**Created:** [June 24, 2023, 2:10pm UTC](https://community.mp3tag.de/t/regexp-returns-full-field-on-no-match-instead-of-blank-null/61359 "2023-06-24T14:10:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nojwe](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@nojwe](https://community.mp3tag.de/u/nojwe)\
**Post date:** [June 24, 2023, 2:10pm UTC](https://community.mp3tag.de/t/regexp-returns-full-field-on-no-match-instead-of-blank-null/61359/1 "2023-06-24T14:10:54Z")

</div>

If I have a title of `Symphonie Fantastique - I. Reveries - Passions` and run a tag to tag function with a format string of  
`$regexp(%title%,'^.?\b(Concerto|Symphony|Suite|Sonata|Quartet|Quintet|Trio)\b.*',$1)`  
It returns `Symphonie Fantastique - I. Reveries - Passions`, instead of a blank or null string, as I'd expect. Is this expected behavior? Is there a way to get it to return an empty/null string if a match is not found?

My workaround is:  
`$iflonger($trim($regexp(%title%,'^.?\b(Concerto|Symphony|Suite|Sonata|Quartet|Quintet|Trio)\b.*',$1)),0,$regexp(%title%,'^.?\b(Concerto|Symphony|Suite|Sonata|Quartet|Quintet|Trio)\b.*',$1),'')`

It works, but is kind of complicated. Any ideas?

---

<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, 2023, 2:18pm UTC](https://community.mp3tag.de/t/regexp-returns-full-field-on-no-match-instead-of-blank-null/61359/2 "2023-06-24T14:18:38Z")

</div>

> [@nojwe](#):
>
> Is this expected behavior?

Yes.  
And so you have to test the success like you did.

---

<div class="post-metadata">

**Author:** ![nojwe](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@nojwe](https://community.mp3tag.de/u/nojwe)\
**Post date:** [June 25, 2023, 1:42am UTC](https://community.mp3tag.de/t/regexp-returns-full-field-on-no-match-instead-of-blank-null/61359/3 "2023-06-25T01:42:19Z")

</div>

Thanks for confirming!

---

<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, 2023, 2:46pm UTC](https://community.mp3tag.de/t/regexp-returns-full-field-on-no-match-instead-of-blank-null/61359/4 "2023-06-25T14:46:20Z")

</div>

The regular expression looks for a pattern and if there is a match for the pattern, then the next instruction is carried out.  
There is no explicit indicator that a pattern has not been found - it would not be clear to me how often such an event should be triggered and reported.  
Also, I would not like the regular expression simply delete the input if no match is found but to leave the input the way it is.  
So, your observation that the whole input is returned when there is no match, is correct.

---

<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, 2023, 2:46pm UTC](https://community.mp3tag.de/t/regexp-returns-full-field-on-no-match-instead-of-blank-null/61359/5 "2023-07-25T14:46:39Z")

</div>

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