79112530

Date: 2024-10-22 05:25:09
Score: 0.5
Natty:
Report link
import ballerina/lang.regexp;

function extractContentDispositionParams(string contentDisposition) returns map<string> {
    map<string> params = {};
    string[] parts = regexp:split(re `;`, contentDisposition);

    foreach string part in parts {
        string[] keyValue = regexp:split(re `=`, part.trim());
        if (keyValue.length() == 2) {
            string key = keyValue[0].trim();
            string value = re `"`.replace(keyValue[1].trim(), "");
            params[key] = value;
        }
    }

    return params;
}

You can learn more about Ballerina regex in here.

https://ballerina.io/learn/by-example/regexp-type/ https://central.ballerina.io/ballerina/lang.regexp/latest

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Sasindu Dilshara