# I need help with regular expressions and formatting

**URL:** <https://community.glideapps.com/t/i-need-help-with-regular-expressions-and-formatting/62863>\
**Category:** Ask for Help\
**Created:** [June 17, 2023, 7:12am UTC](https://community.glideapps.com/t/i-need-help-with-regular-expressions-and-formatting/62863 "2023-06-17T07:12:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ToOFa\_Apps](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/toofa_apps/32/36816_2.png) [@ToOFa\_Apps](https://community.glideapps.com/u/ToOFa_Apps)\
**Post date:** [June 17, 2023, 7:12am UTC](https://community.glideapps.com/t/i-need-help-with-regular-expressions-and-formatting/62863/1 "2023-06-17T07:12:22Z")

</div>

I am using this Extract matching text column to clean up cell number formats but it’s not quite doing the trick. This format +27 (73) 899-2999 should be formatted like this 738992999  
No matter what numbers and characters they enter, i really just need the last nine numbers from their entry.  
Any ideas? @Darren_Murphy or anyone else who could help?

 ![Screenshot 2023-06-17 at 08.35.15](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/8/7/87da66537c54d30a4570e105578754e3d1984985.png)

---

<div class="post-metadata">

**Author:** ![Eric\_Penn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/eric_penn/32/73888_2.png) [@Eric\_Penn](https://community.glideapps.com/u/Eric_Penn)\
**Post date:** [June 18, 2023, 1:25pm UTC](https://community.glideapps.com/t/i-need-help-with-regular-expressions-and-formatting/62863/2 "2023-06-18T13:25:26Z")

</div>

I’m looking for same thing… RegEx to clean phone number 🙏

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [June 18, 2023, 1:55pm UTC](https://community.glideapps.com/t/i-need-help-with-regular-expressions-and-formatting/62863/3 "2023-06-18T13:55:53Z")

</div>

I started having a look at this yesterday, and ended up going down a bit of a rabbit hole, so I put it aside.

Had another look just now and it occurred to me that all you really need to do is strip out all the non-digits and then return the last 9 characters of whatever is remaining. So with that in mind, here is a bit of rough and ready JavaScript that does that. I’m sure it could be improved.

```auto
const parts = p1.split('');
let digits = [];
while (parts.length > 0) {
  let bit = parts.shift();
  if (bit.match(/\d/)) {
    digits.push(bit);
  }
}
return digits.slice(-9).join('');

```

 ![CleanShot 2023-06-18 at 21.51.48@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/e/3e0300ad4a5aff2beeb28326c1941c12b4977f5a.png)

---

<div class="post-metadata">

**Author:** ![Eric\_Penn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/eric_penn/32/73888_2.png) [@Eric\_Penn](https://community.glideapps.com/u/Eric_Penn)\
**Post date:** [June 18, 2023, 2:38pm UTC](https://community.glideapps.com/t/i-need-help-with-regular-expressions-and-formatting/62863/4 "2023-06-18T14:38:04Z")

</div>

Much obliged 🧐

---

<div class="post-metadata">

**Author:** ![ToOFa\_Apps](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/toofa_apps/32/36816_2.png) [@ToOFa\_Apps](https://community.glideapps.com/u/ToOFa_Apps)\
**Post date:** [June 19, 2023, 8:50am UTC](https://community.glideapps.com/t/i-need-help-with-regular-expressions-and-formatting/62863/5 "2023-06-19T08:50:06Z")

</div>

Genius, this works like a charm.  
I am seeing this yellow banner, have i set it up correctly? It’s working fine even with the Error banner. Any ideas?

 ![Screenshot 2023-06-19 at 10.45.36](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/8/58849662d56417b2126b6c66beda6355873c4828.png)

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [June 19, 2023, 9:04am UTC](https://community.glideapps.com/t/i-need-help-with-regular-expressions-and-formatting/62863/6 "2023-06-19T09:04:16Z")

</div>

Do you have any rows that don’t have a value in the Phone Number column?  
Empty rows would cause that error. You could add a return statement in the code to avoid that, but it isn’t really necessary.

---

<div class="post-metadata">

**Author:** ![ToOFa\_Apps](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/toofa_apps/32/36816_2.png) [@ToOFa\_Apps](https://community.glideapps.com/u/ToOFa_Apps)\
**Post date:** [June 19, 2023, 9:43am UTC](https://community.glideapps.com/t/i-need-help-with-regular-expressions-and-formatting/62863/7 "2023-06-19T09:43:02Z")

</div>

Yes i have blank rows. The cell number is an optional field.  
Besides that it’s all working fine. I’ll test for a while and see, seems all good though👍

---

<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:** [June 20, 2023, 9:43am UTC](https://community.glideapps.com/t/i-need-help-with-regular-expressions-and-formatting/62863/8 "2023-06-20T09:43:34Z")

</div>

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