Help Extract with regex

Hi there, I need help to extract a value with regex, chatgpt response doesn’t work.

Text to parse:
“{"code":"ERROR_CODE_INPUT_ERROR","message":"Input does not meet minimum length requirement of 8 characters","payload":{"param":"password"}}”

Expected return:
Input does not meet minimum length requirement of 8 characters

ChatGPT answer:
“message”\s*:\s*“([^”]*)"

Thanks!

Thats odd. The only problem with the regex pattern you quoted is that its using curly quotation marks ’ “ ’ instead of normal quotation marks ’ " '.

But on bubble you are using the right quotation marks so it should work.

Anyways, try with this regex pattern:
"message":"([^"]+)"

You don’t need the \s* anyways, thats just matching 0+ newline characters, i dont know why chatGPT put that.

Use this page to test. I recommend it

This returns the key along with value: "message":"Input does not meet minimum length requirement of 8 characters"

This (?<=\"message\":\")[^\"]* strips the key out and just returns the Input does not meet minimum length requirement of 8 characters

Solution from: regex - how to use a regular expression to extract json fields? - Stack Overflow

And just for the heck of it without regex… :slight_smile:

split-by

The :find & replace operator finds message":" and replaces it with nothing.

Cool solution. Wouldn’t work if the json response is changing time to time, right? (i.e. new key-vals before message)

Yup, definitely true… just food for thought, though, because I really dig the :split by operator. :slight_smile:

1 Like

Works great, thanks guys! :slight_smile:

Since you are fond of split by here is another solution that can handle changes in the json structure:
((Input A's value : split by ("message":") :item #2) :split by (") :first item)

2 Likes