Useful Regular Expressions

I thought it might be helpful to have a topic where we could collect regular expressions that we have found useful. I just needed a formula to remove a number from the end of some text, so I came up with this:

regexreplace(sometext,"[0-9]+$","")

If sometext is abc12, the result will be abc

If *sometext is a89bcd12, the result will be a89bcd

So only numbers at the end of the text will be removed. Numbers in the middle will not be removed.

Here’s how this works:

[0-9]+

means match one or more characters that are numeric digits (from 0 to 9).

$

means that the match must be at the end of the text.

Since the regexreplace( function is being used, the matching text will be replaced, in this case with nothing.

Good idea - it would certainly be a help to anyone who wants to learn RegEx, and we all should, given how powerful they are.

Will this be a sticky post or will you rely on frequency of contribs?

I hadn’t even thought about that. Let’s see how it goes.