0

I have a question regarding REGEXP_SUBSTR in redshift. I have a string, and I want to always return the last substring 'STATUS CHANGE FROM ''something'' TO ''another thing''. There might be multiple substring in the string. I only need to return the last one.

select REGEXP_substr(' sfdfgdfg STATUS CHANGE FROM ''REGISTERED'' TO ''DISABLED'' ZD# 17564 REASON: CUSTO STATUS CHANGE FROM ''DISABLED'' TO ''HOLD'' ', 'STATUS CHANGE FROM ''\w+'' TO ''\w+'' ');

The current code return nothing. Can someone help me take a look?

Thank you very much.

1 Answer 1

0

If I understand you, I believe all you need is to anchor your pattern to the end of the line. This is based on your one line of test data. Note the dollar sign.

select REGEXP_substr(' sfdfgdfg STATUS CHANGE FROM ''REGISTERED'' TO ''DISABLED'' ZD# 17564 REASON: CUSTO STATUS CHANGE FROM ''DISABLED'' TO ''HOLD'' ', 'STATUS CHANGE FROM ''\w+'' TO ''\w+'' $');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.