@abaplint/runtime
Version:
Transpiler - Runtime
26 lines • 754 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.match = match;
const string_1 = require("../types/string");
function match(input) {
const val = typeof input.val === "string" ? input.val : input.val.get();
const regexInput = input.pcre || input.regex;
if (regexInput === undefined) {
throw "match() requires either regex or pcre parameter";
}
let reg = "";
if (typeof regexInput === "string") {
reg = regexInput;
}
else {
reg = regexInput.get();
}
const r = new RegExp(reg);
const res = val.match(r);
let ret = "";
if (res && res[0]) {
ret = res[0];
}
return new string_1.String().set(ret);
}
//# sourceMappingURL=match.js.map