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
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.
hergin
February 2, 2024, 10:03pm
3
nico.dicagno:
"message":"([^"]+)"
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
mikeloc
February 2, 2024, 10:11pm
4
And just for the heck of it without regex…
The :find & replace operator finds message":" and replaces it with nothing.
hergin
February 2, 2024, 10:14pm
5
Cool solution. Wouldn’t work if the json response is changing time to time, right? (i.e. new key-vals before message)
mikeloc
February 2, 2024, 10:15pm
6
Yup, definitely true… just food for thought, though, because I really dig the :split by operator.
1 Like
Works great, thanks guys!
hergin
February 4, 2024, 2:22am
8
mikeloc:
find & replace
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
system
Closed
April 12, 2024, 9:30pm
9
This topic was automatically closed after 70 days. New replies are no longer allowed.