cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Extract string from between two other strings

klandry
Deputy Chef II
Deputy Chef II

In a recipe, there is an error that is being returned in a datapill from an API call.
I want to extract just the error "text".

Here is a snippet of the string that is being returned:

,\"ErrorMessage\":\"Item KL65512 is not valid\",

I want to end up with:
Item KL65512 is not valid

 
I was looking at .scan, but I cannot seem to get the correct syntax to achieve what I am looking for.
Any help is appreciated.
1 ACCEPTED SOLUTION

gary1
Executive Chef III
Executive Chef III

This will work with the snippet provided, but without knowing the rest of the string I can't promise it will always work.

message.scan(/\"ErrorMessage\\\":\\\"(.*?)\\\",/)

I recommend parsing the API response instead, so this comes across as an actual data pill.

View solution in original post

2 REPLIES 2

gary1
Executive Chef III
Executive Chef III

This will work with the snippet provided, but without knowing the rest of the string I can't promise it will always work.

message.scan(/\"ErrorMessage\\\":\\\"(.*?)\\\",/)

I recommend parsing the API response instead, so this comes across as an actual data pill.

klandry
Deputy Chef II
Deputy Chef II

Thank you Gary. The snippet that I provided is unique in the string so I avoided posting the entire string.
I had gotten close to what you are suggesting and both seem to product the desired outcome.
.scan(/ErrorMessage\\\"\:\\\"([^\"]+)\\\"/)

The API response is available in the form of a datapill, but I could not find a way to get just that text without REGEX.

Thank You