# Find text in string, delete it and everything after it

**URL:** https://community.mp3tag.de/t/find-text-in-string-delete-it-and-everything-after-it/17566
**Category:** General Discussion
**Created:** [January 17, 2016, 3:45pm UTC](https://community.mp3tag.de/t/find-text-in-string-delete-it-and-everything-after-it/17566 "2016-01-17T15:45:51Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tonymp3tag](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/t/dbc845/32.png) [@tonymp3tag](https://community.mp3tag.de/u/tonymp3tag)
#### Post date: [January 17, 2016, 3:45pm UTC](https://community.mp3tag.de/t/find-text-in-string-delete-it-and-everything-after-it/17566/1 "2016-01-17T15:45:51Z")

</div>

Hi  
I am sure this is possible, just cannot get it to work.  
In the tag “UNSYNCEDLYRICS” I want to find the first occurrence of text in the string say “threebears” then delete everything including the text to the end  
For example “Once upon a time there was threebears mummy bear, daddy bear”  
To “Once upon a time there was”  
Don’t mind creating a new action , but ideally would like to incorporate into an Export Script I have written in File – Export  
Thanks

---

<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: [January 17, 2016, 4:18pm UTC](https://community.mp3tag.de/t/find-text-in-string-delete-it-and-everything-after-it/17566/2 "2016-01-17T16:18:38Z")

</div>

Create an action of the type "Replace with regular expression" or use a $regexp() statement:  
Search string: threebears .\*$  
Replace string:  
(leave empty)

$regexp(%unsyncedlyrics%,'threebears.\*',)

---

<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: [January 17, 2016, 5:39pm UTC](https://community.mp3tag.de/t/find-text-in-string-delete-it-and-everything-after-it/17566/3 "2016-01-17T17:39:07Z")

</div>

> [@Tony\_](#):
>
> ... In the tag “UNSYNCEDLYRICS” I want to find the first occurrence of text in the string say “threebears” then delete everything including the text to the end.  
> For example “Once upon a time there was threebears mummy bear, daddy bear”  
> To “Once upon a time there was” ...

**Convert "Tag - Tag" ... or ... Action "Format value" Field: UNSYNCEDLYRICS Formatstring: $trimRight($left(%UNSYNCEDLYRICS%,$sub($strstr(%UNSYNCEDLYRICS%,'threebears'),1))) ... or ... Formatstring: $trimRight($regexp(%UNSYNCEDLYRICS%,'^(.\*?)threebears.\*','$1')) ... or ... Formatstring: $trimRight($regexp(%UNSYNCEDLYRICS%,'threebears.\*',)) From: 'eng||Once upon a time there was threebears mummy bear, daddy bear ...' To : 'eng||Once upon a time there was'**

DD.20160117.1944.CET

---

<div class="post-metadata">

### Author: ![tonymp3tag](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/t/dbc845/32.png) [@tonymp3tag](https://community.mp3tag.de/u/tonymp3tag)
#### Post date: [January 17, 2016, 6:04pm UTC](https://community.mp3tag.de/t/find-text-in-string-delete-it-and-everything-after-it/17566/4 "2016-01-17T18:04:40Z")

</div>

Hi  
Thanks to you both, Excellent, just been playing around with what I wanted to achieve, and now working.  
Thanks for your help – appreciated.
