# 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:** 1\
**Showing post:** 3

<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)

---

_[View the full topic](https://community.glideapps.com/t/i-need-help-with-regular-expressions-and-formatting/62863)._
