Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

REGEXP_SUBSTR assistance

This is probably pretty simple for most, but I’m just not great at regular expressions.

I have a set of strings with this type of format:

SYND_YAHOO_7BEST_RANKADDITIONS_268_2357425

So basically I want to search the string and extract the pattern _###_. Note that there can be 1 digit, or 2 or 3 or 4, etc. I know REGEXP_SUBSTR will do it for me, just not sure of the simple expression to use.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks!

>Solution :

Assuming 268 is your desired match, a fairly simple pattern will work. Below returns the group of digits between underscores at the end of the string in the first capture group.

.*_(\d+)_.*$

https://regex101.com/r/gMCzdD/1

The main key here is that we start with .* which matches aggressively "as many times as possible" meaning that we’ll capture the last occurrence of digits between underscores, even if the same pattern occurs earlier in the string.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading