Start integrating with ONEiO for free!
SIGN UP

Useful Regex search strings

Intro

Here are some useful search strings with regular expressions. We will continue to update this article as when we have more examples to share.

Example 1 - Extract text with regular expression

Regex

"detail":"(.*?)"

Test String

Bad Request (400) occurred while sending message. 
Response body: '{"error":{"detail":"The following error(s) occurred; 
Attachment exceeds the maximum size limit of 10MB",
"message":"Unacceptable request"},
"status":"failure"}

Result / Match

The following error(s) occurred; 
Attachment exceeds the maximum size limit of 10MB

TAKE NOTE

If you wanted to extract only string from message, i.e Unacceptable request, the regex to match that string will be "message":"(.*?)"

 

Example 2 - Extract text with regular expression

Regex

"message":"(.*?)"

Test String

Sending failed. 
Authorization/authentication failure when sending message to URI:
'null' with status code: '401' occurred while sending message.
Response body: '{"error":{"message":"User Not Authenticated","detail":
"Required to provide Auth information", "status" "failure"}'

Result / Match

User Not Authenticated

 

TAKE NOTE

If the JSON is using extra white-spaces after the colon, then include that in the regex to match correctly.
"name of the attribute": "(.*)"

 

Example 3 - Extract text with regular expression and using Replace all occurrences of regular expression with string or empty string

Regex

Extract text with regular expression (?:.*Response body: ')(.*)(?:')
Replace all occurrences of regular expression \{\"errors\":\[ with
Replace all occurrences of regular expression \]\} with
Replace all occurrences of regular expression ({"status":\d\d\d\,) with
Replace all occurrences of regular expression ("field":"\w*(\.\w*){0,}",) with
Replace all occurrences of regular expression "message": with
Replace all occurrences of regular expression } with

  • Each of the "Replace all occurrences of" add-on filters have the use source as regex checked
  • Essentially, we are replacing all the occurrences of a string that match the regular expression with (insert_regular_expression_here) with an empty string ("") so leave the text field after with empty.

How it appears in the ONEiO UI

Screenshot 2023-08-11 at 17.03.31.png

Test String

In this use case, we want to extract all the values from the message attribute. When testing with the string below, you essentially are going through each of the filters so the results from first filter will be used as the test string for the second filter and that process repeats until you have arrived last result which will be the value that is saved to the runtime variable as seen in the example above in the UI.

Bad Request (400) occurred while sending message. Response body: '{"errors":[{"status":400,"field":"paymentDetails","message":"Invalid Account"},{"status":400,"field":"shippingAddress","message":"Missing House number"},{"status":400,"message":"Invalid Id"},{"status":400,"field":"expiryDate","message":"Invalid expiry date format"},{"status":400,"field":"registrationCode","message":"Invalid expiry date format"}]}'

 

Result / Match

"Invalid Account","Missing House number","Invalid Id","Invalid expiry date format","Invalid registration code"
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.