Mano
Mano

Reputation: 711

How to extract numbers after string using regexp?

I need to extract the number/numbers that come after the last letter in a given string, using regexp or any other possible function.

For example, if the string is 'a23kfj879lp999', I need only 999 since the last letter in the string is p.

Upvotes: 0

Views: 1518

Answers (1)

Razvan
Razvan

Reputation: 2596

Use the REGEX_SUBSTR function:

SELECT REGEXP_SUBSTR('a23kfj879lp999', '([0-9]+)$') FROM dual

Explanation:

REGEX_SUBSTR simply extracts the first substring from the source string that matches the respective pattern.

Syntax:

REGEXP_SUBSTR( string, pattern [, start_position [, nth_appearance [, match_parameter [, sub_expression ] ] ] ] )

Upvotes: 1

Related Questions