extractx() “g” flag workaround

Ninox Profile

Here is a basic UDF for extracting all of the values that match a regex pattern...

 

function extractxg(src : text,regex : text) do
let extValue := “”;
let idx := 0;
let idxLen := 0;
while testx(src, regex) do 
idx := index(src, extractx(src, regex));
idxLen := length(extractx(substr(src, idx), regex));
extValue := extValue + extractx(substr(src, idx), regex) + “,”;
src := substr(src, idx + idxLen)
end
;
if extValue = “” then
extValue := null
else
extValue := substr(extValue, 0, length(extValue) - 1)
end;
extValue
end

 

Using this example...


let myVar := “a23B65nm87”;
extractxg(myVar, “\D+”)

 

a,B,nm is returned as a concatenated string.

Reply