Use regular expression to extract int values from UUID?

Hi. I am creating a composite ID and I need a final 5 digit random ID for my project (just unique within a village of 200 surveys). We forked ODK Collect a number of years ago and it seems that format-date-time wasn't supported and format-date rounds off the time elements. So, could I use a regular expression to pull out just int values from the UUID alpha-numeric string? I need 4-5 integers.

Thanks!
Alex

You cannot use regex to pull out individual numbers because it returns true/false.

You can try getting the number of days (including fractional days), then multiply by 100 to remove the decimal, then grab the last five digits. So roughly, you'd have two calculates like this:

$days = string(decimal-date-time(now())*100)
$digits = substr($days, string-length($days)-5)

This all assumes that your fork has these functions. It might be worth it to have whomever who is maintaining the fork try this out.

1 Like

I wanted to post my solution in case someone is looking for this in the future.

"<bind nodeset="/data/meta/randomnum" type="string" calculate="substr(random(),3,8)" / (add the last >)

This will give you a random string of 5 int values.
I then used it to create a composite string

<bind nodeset="/data/p_GenerateID" type="string" required="true()" readonly="true()" relevant="(selected(/data/p_IDMethod, 'IDGeneration'))" calculate="concat(/data/p_RecorderID, '-', /data/p_ClusterID, '-', /data/meta/randomnum)"/ (add the last >)

Let me know if you have any trouble.