# Removing all numbers from a sentence

**URL:** https://community.glideapps.com/t/removing-all-numbers-from-a-sentence/64689
**Category:** Ask for Help
**Created:** [August 4, 2023, 4:11am UTC](https://community.glideapps.com/t/removing-all-numbers-from-a-sentence/64689 "2023-08-04T04:11:14Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Brandon](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/brandon/32/58098_2.png) [@Brandon](https://community.glideapps.com/u/Brandon)
#### Post date: [August 4, 2023, 4:11am UTC](https://community.glideapps.com/t/removing-all-numbers-from-a-sentence/64689/1 "2023-08-04T04:11:14Z")

</div>

Hello I am trying to use the Java Script to grab all phone numbers and or emails from a description text. I can’t seem to get the function right any guidance for help here from the community?

```auto
function removePhoneNumbersAndEmails(text) {
  const phoneRegex = /(\+\d{1,2}\s?)?(\()?(\d{3})(?(2)\))[-.\s]?(\d{3})[-.\s]?(\d{4})\b/g;
  const emailRegex = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g;

  // Remove phone numbers
  text = text.replace(phoneRegex, '');

  // Remove email addresses
  text = text.replace(emailRegex, '');

  return text.trim();
}

// Test the function with an example text
const text = `
  This is a sample text.
  You can contact me at +1 (123) 456-7890 or john.doe@example.com.
  Please reach out to p1 for more information.
`;

const result = removePhoneNumbersAndEmails(text);
console.log(result);

```

---

<div class="post-metadata">

### Author: ![Brandon](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/brandon/32/58098_2.png) [@Brandon](https://community.glideapps.com/u/Brandon)
#### Post date: [August 4, 2023, 4:38am UTC](https://community.glideapps.com/t/removing-all-numbers-from-a-sentence/64689/2 "2023-08-04T04:38:46Z")

</div>

You can fix this issue by using google sheets functions.

This function hides all contact information  
email  
Phone  
address

=REGEXREPLACE(A2, “\b(?:\d\s?){9}\b|\b(?:+?\d{1,2}\s?)?(?:(\d{3})|\d{3})[-.\s]?\d{3}[-.\s]?\d{4}\b|\b\d+\s+[\w\s]+,\s+[\w\s]+,\s+[\w\s]+”, “[hidden]”)

---

<div class="post-metadata">

### Author: ![Brandon](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/brandon/32/58098_2.png) [@Brandon](https://community.glideapps.com/u/Brandon)
#### Post date: [August 4, 2023, 5:44am UTC](https://community.glideapps.com/t/removing-all-numbers-from-a-sentence/64689/3 "2023-08-04T05:44:15Z")

</div>

This Gsheet functione is better:

Hides the following:  
Curse words  
Addresses  
Websites  
Emails  
Phone numbers

=ArrayFormula(IF(A2:A=“”, “”, REGEXREPLACE(A2:A,“\b(?:\d\s?){9}\b|\b(?:+?\d{1,2}\s?)?(?:(\d{3})|\d{3})[-.\s]?\d{3}[-.\s]?\d{4}\b|\b\d+\s+[\w\s]+,\s+[\w\s]+,\s+[\w\s]+|((?:https?|ftp)://)?[\w-]+(.[\w-]+)+([\w.,@?^=%&:/~+#-]\*[\w@?^=%&/~+#-])?|\b[A-Za-z0-9.\_%±]+@[A-Za-z0-9.-]+.[A-Za-z]{2,}\b|\b(?:Cunt|nigger|Nigger|Fuck|Pussy|Bitch|Boobs|Nig|nig|Bitch|Steal|steal|liar|thief|fuck|pussy|bitch|cracker|tits|boobs|…)\b”, “[hidden]”)))

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [August 5, 2023, 1:58am UTC](https://community.glideapps.com/t/removing-all-numbers-from-a-sentence/64689/4 "2023-08-05T01:58:03Z")

</div>

> [@Grab phone numbers and email from text](https://community.glideapps.com/t/grab-phone-numbers-and-email-from-text/64686/2):
>
> My way of doing this is using a text prompt and OpenAI: Given an input like this: "{I}" Can you return a JSON structure of all phone numbers and emails in the input? A sample structure would look like this: { "phone": "+123456789,+123456790", "email": "example@gmail.com,example2@gmail.com" } Please return just the JSON and nothing else. notalk;justgo. Then you can query the JSON to return the final strings.

Please try this to see if it works for your case.

I would try to move as many functions as possible to Glide’s computed columns instead of Google Sheets.

---

<div class="post-metadata">

### Author: ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)
#### Post date: [August 12, 2023, 1:58am UTC](https://community.glideapps.com/t/removing-all-numbers-from-a-sentence/64689/5 "2023-08-12T01:58:42Z")

</div>

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