You are viewing limited content. For full access, please sign in.

Question

Question

Extract last two numbers from Token

asked on August 2, 2023

Hi all,

New to expressions,  not sure why this isn't fully working.

 

I'm trying to extract the last 2 or 1 numbers from a string. It seems to work if there are 2 numbers but not 1?

 

Any help appreciated.

 

Thanks

 

0 0

Answer

SELECTED ANSWER
replied on August 3, 2023 Show version history

Your expression is implicit that it is looking for 2 digits at the end.

You can make the expression more flexible by using \d{1,2}$

- this means the it is looking for 1 or 2 digits at the end of the string

or \d?\d$

- the ? means Optional, so it says it's looking for 1 digit at the end with an option for a digit in front of it.

5 0

Replies

replied on August 3, 2023

Thank you Steve, 

 

Perfect, thanks for the explanation, that is very helpful.

 

Much appreciated

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.