# Remove a Date from a String

**URL:** <https://forums.knack.com/t/remove-a-date-from-a-string/13282>\
**Category:** Get Answers\
**Created:** [October 22, 2022, 9:17am UTC](https://forums.knack.com/t/remove-a-date-from-a-string/13282 "2022-10-22T09:17:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnG](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@JohnG](https://forums.knack.com/u/JohnG)\
**Post date:** [October 22, 2022, 9:17am UTC](https://forums.knack.com/t/remove-a-date-from-a-string/13282/1 "2022-10-22T09:17:34Z")

</div>

I have a Text String that sometimes contains a Date, if it exists I want to remove it.

Example: word1 word2 07/11/2022 word3, Convert to: word1 word2 word3

Sounds simple but I just cant figure it out.

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![Sunny\_Singla](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/sunny_singla/32/1007_2.png) [@Sunny\_Singla](https://forums.knack.com/u/Sunny_Singla)\
**Post date:** [October 22, 2022, 6:23pm UTC](https://forums.knack.com/t/remove-a-date-from-a-string/13282/2 "2022-10-22T18:23:38Z")

</div>

Hello John,

create a formula field and regex there  
regexReplace({Test Regex},((0[1-9][\])|([12][0-9][\])|(3[01][\]))((0[0-9][\])|(1[012][\]))((20[012]\d|19\d\d)|(1\d|2[0123])) , )

{Test Regex} is your field containing date examples. works for dd/mm/yyyy format. You need to create regex for other formats

Thanks,  
Sunny Singla

---

<div class="post-metadata">

**Author:** ![JohnG](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@JohnG](https://forums.knack.com/u/JohnG)\
**Post date:** [October 23, 2022, 8:56am UTC](https://forums.knack.com/t/remove-a-date-from-a-string/13282/3 "2022-10-23T08:56:11Z")

</div>

Wow, thanks for getting back so quick Sunny, I have tried it and it it only extracts the year leaving the month and day!  
However, using that as a template I have found this works: regexReplace({Test String},(\d{1,2})/(\d{1,2})/(\d{4}), )

Although that was more luck than judgement 🙂

Thanks

John

---

<div class="post-metadata">

**Author:** ![Sunny\_Singla](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/sunny_singla/32/1007_2.png) [@Sunny\_Singla](https://forums.knack.com/u/Sunny_Singla)\
**Post date:** [October 23, 2022, 10:23am UTC](https://forums.knack.com/t/remove-a-date-from-a-string/13282/4 "2022-10-23T10:23:43Z")

</div>

It’s works for me for dd/mm/yyyy format… your regex works for mm/dd/yyyy for mad dd/mm/yyyy as well as wrong date as well…

Like 20/20/2022

---

<div class="post-metadata">

**Author:** ![JohnG](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@JohnG](https://forums.knack.com/u/JohnG)\
**Post date:** [October 23, 2022, 11:28am UTC](https://forums.knack.com/t/remove-a-date-from-a-string/13282/5 "2022-10-23T11:28:55Z")

</div>

Ahhh I see why now I am writing apps for companies in the US as well as UK so my version should work for both.

Thanks for you help Sunny.

---

<div class="post-metadata">

**Author:** ![JohnG](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@JohnG](https://forums.knack.com/u/JohnG)\
**Post date:** [October 24, 2022, 8:30am UTC](https://forums.knack.com/t/remove-a-date-from-a-string/13282/6 "2022-10-24T08:30:38Z")

</div>

Hi again Sonny, I know we sorted the last challenge but working on the same text field I wanted to extract another string that was appearing: “-\<”, I have tried it using extract: extract({test\_field},-\<, ) but when I save the field and reopen it I see: extract({test\_field},- same with RegexReplace.

When I go to [rubular.com](http://rubular.com) I have a string that works there but not in Knack, all I get after saving and opening is RegexReplace({test\_field},-

 ![Screenshot 2022-10-24 at 09.28.06](https://us1.discourse-cdn.com/flex020/uploads/knack/original/2X/b/ba88c7ed40eb38492c652d5eb957b972b5793895.png)

I have tried escaping it with a backslash but to no avail.

Any Ideas?

John

---

<div class="post-metadata">

**Author:** ![Sunny\_Singla](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/sunny_singla/32/1007_2.png) [@Sunny\_Singla](https://forums.knack.com/u/Sunny_Singla)\
**Post date:** [October 24, 2022, 9:19am UTC](https://forums.knack.com/t/remove-a-date-from-a-string/13282/7 "2022-10-24T09:19:42Z")

</div>

Hello john,

For this, you need to create an extra formula field.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/knack/original/2X/1/142ffa6fd26a7cdedd8ce6e8876da00708d217b8.png)  
then  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/knack/original/2X/b/b756d44890bc0c93be0365463e5dce8fa3265a5a.png)

for some reason, knack does not support \< character. so we need to create an extra field.

Regards,  
Sunny Singla

---

<div class="post-metadata">

**Author:** ![JohnG](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@JohnG](https://forums.knack.com/u/JohnG)\
**Post date:** [October 24, 2022, 11:37am UTC](https://forums.knack.com/t/remove-a-date-from-a-string/13282/8 "2022-10-24T11:37:38Z")

</div>

Hi Sunny

Thanks for that it works a treat although I did make a small modification to the above, I am always wary of too many calculation fields slow things down so I have made the formula field a text field and populated it on creation.

As always many thanks for your time and sharing your knowledge.

John
