# Regex to Remove Number from String

**URL:** https://community.glideapps.com/t/regex-to-remove-number-from-string/36310
**Category:** Ask for Help
**Created:** [December 24, 2021, 2:49am UTC](https://community.glideapps.com/t/regex-to-remove-number-from-string/36310 "2021-12-24T02:49:34Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)
#### Post date: [December 24, 2021, 2:49am UTC](https://community.glideapps.com/t/regex-to-remove-number-from-string/36310/1 "2021-12-24T02:49:34Z")

</div>

Regex is not something I’ve ever taken the time to learn. I’m trying to do something that I hope is simple.

I have a string that’s something like this:  
`2021 Competition Name`

What I want is to remove the leading year as well as the space following it, so it looks like this:  
`Competition Name`

At best I can get regex to remove the leading year, but I can’t figure out how to also remove the space, so right now I end up with this:  
`•Competition Name` (The dot is a space)

I can create another column to trim whitespaces, and that works fine, but I was hoping to accomplish the removal of the year as well as the trim with a single regex column.

I was wondering if anybody had any insight on how to accomplish this.

---

<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: [December 24, 2021, 2:57am UTC](https://community.glideapps.com/t/regex-to-remove-number-from-string/36310/2 "2021-12-24T02:57:56Z")

</div>

~~`^[/d/s]+` should do it.~~

Sorry, toothpicks back to front. It should be `^[\d\s]+`

Breaking that down:

- `^` match the start of the string
- `[]` consider characters as a group
- `\d` any decimal digit
- `\s` any white space character
- `+` match preceding character/group one or more times

“from the start of the string, match any sequence of digits and/or whitespace characters”

---

<div class="post-metadata">

### Author: ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)
#### Post date: [December 24, 2021, 3:25am UTC](https://community.glideapps.com/t/regex-to-remove-number-from-string/36310/3 "2021-12-24T03:25:00Z")

</div>

That’s not working for me. Here is a little more context. What I’m trying to do is replace some old vlookup that was combines with some regex logic in my sheet. What’s supposed to happen is that I take a competition name, that includes a year, strip off the year, and then ultimately use that stripped value to create a relation to an Images resource table. The competition is year based, but the image for each particular competition remains the same. This allows a user to create a new competition record, with a name that includes the year, but pulls from the same images resource.

This is what I am using. It extracts everything BUT the year, which is what I want. But it obviously still includes the space between the year and the rest of the string, because it’s not numeric.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/e/3/e380beb3e03ea98f99d880911e6dfd2bbffb8976.png)

Using your regex, it instead returns only the decimal digits and the space, which is the opposite of what I’m looking for.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/4/2/428388840999a08976b0524e11c182dbef521256.png)

Hope that makes mores sense. Right now, I can take the regex result from `(\D+)` and then use the trim plugin, so I’m completely fine with that method, but I wanted to see if I could do it all within the regex extract.

---

<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: [December 24, 2021, 3:27am UTC](https://community.glideapps.com/t/regex-to-remove-number-from-string/36310/4 "2021-12-24T03:27:01Z")

</div>

You need to get rid of the capturing parentheses, and use a different plugin. Use the Replace All plugin with the regex that I gave you.

Or, to do it with the plugin you’re using now, you could use: `^[\s\d]+(.*)`

Example 1: Replace All

 ![Screen Shot 2021-12-24 at 11.30.53 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/9/e/9e5e2f2cd2e4578816736d1551db133df1cf59de.png)

Example 2: Extract Matching text

 ![Screen Shot 2021-12-24 at 11.33.28 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/b/5bff7a7c88db3f16f61ae65c166690b7156aa49b.png)

---

<div class="post-metadata">

### Author: ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)
#### Post date: [December 24, 2021, 3:33am UTC](https://community.glideapps.com/t/regex-to-remove-number-from-string/36310/5 "2021-12-24T03:33:33Z")

</div>

> [@Darren\_Murphy](#):
>
> \[1\]+

That’s the ticket. I was using the wrong plugin. As you can tell, I haven’t dug really deep into the plugins.  
I try to stick to the original glide columns if at all possible. Thanks for the assist!

Your second method works too. I need to sit down sometime and learn regex.

* * *

1. \d\s

---

<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: [December 24, 2021, 3:36am UTC](https://community.glideapps.com/t/regex-to-remove-number-from-string/36310/6 "2021-12-24T03:36:36Z")

</div>

It’s very rare that I have the opportunity to help _you_ with something. Glad I was around at the right time! 😃

---

<div class="post-metadata">

### Author: ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)
#### Post date: [December 24, 2021, 3:37am UTC](https://community.glideapps.com/t/regex-to-remove-number-from-string/36310/7 "2021-12-24T03:37:34Z")

</div>

Hehe, I try to make a best effort to figure something out myself, but this one had me stumped. Glad you were around too!

---

<div class="post-metadata">

### Author: ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)
#### Post date: [December 24, 2021, 3:41am UTC](https://community.glideapps.com/t/regex-to-remove-number-from-string/36310/8 "2021-12-24T03:41:38Z")

</div>

Sometimes I get into a rabbit hole where something seems so dang simple, and I keep searching and trying things without making any progress. Eventually, I begin to question myself, and begin to wonder if what I’m trying to do is even possible.

---

<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: [December 24, 2021, 3:59am UTC](https://community.glideapps.com/t/regex-to-remove-number-from-string/36310/9 "2021-12-24T03:59:45Z")

</div>

haha, yes I can relate to that. In times like that, I find that setting it aside for a while and working on something else almost always helps. Or go for a walk, or sleep on it. Then come back at it with a fresh mind. Inevitably, I find the answer staring me in the face 🤪

As an aside, of those two regex options above, the first would be (ever so) slightly more efficient. That’s because it will stop as soon as it hits the first non-matching character, whereas the second will continue to the end of the string.

---

<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: [December 24, 2021, 4:06am UTC](https://community.glideapps.com/t/regex-to-remove-number-from-string/36310/10 "2021-12-24T04:06:37Z")

</div>

> [@Jeff\_Hager](#):
>
> Your second method works too. I need to sit down sometime and learn regex.

In that case, you’ll be needing a copy of the [bible](https://www.amazon.com/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124). Was pride of place on my bookshelf back in the day 😉

---

<div class="post-metadata">

### Author: ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)
#### Post date: [December 24, 2021, 4:14am UTC](https://community.glideapps.com/t/regex-to-remove-number-from-string/36310/11 "2021-12-24T04:14:07Z")

</div>

I’ll have to check out that book. We use a very small amount of regex at work, and at most, only a couple of the other developers deal with that stuff, so I’ve never had to touch it. Now SQL…on the other hand…I’ve done some crazy things with that. 😉

---

<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: [December 25, 2021, 4:14am UTC](https://community.glideapps.com/t/regex-to-remove-number-from-string/36310/12 "2021-12-25T04:14:37Z")

</div>

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