Talita Oliveira
Talita Oliveira

Reputation: 31

Extract a string after certain word Presto SQL

I'm trying to build a Regex Expression to extract a string after a certain string. The full string I have is:

Your full name (TL submitting form): XXX
What is your vendor location?: Phoenix

The work a want to extract is the vendor location, in the case above would be Phoenix.

I'm using the code below:

LTRIM(RTRIM(REGEXP_EXTRACT(description_text, '(What is your vendor location\?\:)(.*?)(?=)'))) AS vendor_location

The results using this code is:

Task ID.   Date          Vendor location
90836966 2021-05-14. What is your vendor location?:

Thank you

Upvotes: 3

Views: 4974

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626825

You can use

REGEXP_EXTRACT(description_text, 'What is your vendor location\?:\s*(.+)', 1)

See the regex demo.

The What is your vendor location\?:\s*(.+) regex matches

  • What is your vendor location\?: - a What is your vendor location?: literal text
  • \s* - zero or more whitespaces
  • (.+) - Group 1: any one or more chars other than line break chars as many as possible.

The last 1 argument extracts the Group 1 value as a result of the function.

Upvotes: 2

Related Questions