Regex in XLS calculation

Hi all,

How to use Regex in the calculation column of XLSForm to get the value needed instead the boolean returned by the function regex(.,’…’)? So far I ve only seen regex in specifying constraints.

Thank you!

Hello,
As far as we know, it’s specified as returning a boolean: https://getodk.github.io/xforms-spec/#fn:regex

Also pay attention: There is an essential difference in regex behaviour between Collect and Enketo. See previous discussion in community. https://community.kobotoolbox.org/t/regex-problem-in-kobocollect/7140/18. See also support article (at the bottom): https://support.kobotoolbox.org/restrict_responses.html?highlight=regex

2 Likes

@wroos Thanks for the quick answer. Is there any other function that can be used to return the value? or is it just not possible to get it?

Hello,
Maybe substr( ) or substring-before( ) or substring-after( ) or even translate( ) might partly help. See https://getodk.github.io/xforms-spec/#xpath-functions

If it’s numeric type: mod to extract trailing digits and / (division) with round( ) or int( ) to extract leading digits might be useful.

If you tell the community in more detail, please, what you want to do, support may be easier…

1 Like