So I've got an API integration that returns data in a single string field and I'd like to extract sections of the data to put into separate CDT fields. So the string that's returned will look something like this: "Advil 20 MG/ML Oral Suspension". I'd like to retrieve the data before the number, then everything after including the number. I've posted what I have so far below. What I'm wondering is how do I get the index of the first character that's a number? If I get that, then I can figure out the rest. Thanks!
a!forEach( items: rule!NLH_GetPrescriptionDrugs(searchTerm: ri!search).result.body.drugGroup.conceptGroup.conceptProperties, expression: a!forEach( items: fv!item, expression: 'type!{urn:com:appian:types:NLH}NLH_Prescription'( rxcui: fv!item.rxcui, medication: fv!item.synonym ) ) )
Discussion posts and replies are publicly visible
Hi, You can try below code as well.
a!localVariables( local!string:"Advil 20 MG/ML Oral Suspension", find(regexfirstmatch("[0-9]",local!string),local!string) )
Neater...but if the string contains no numbers it throws an error:
a!localVariables( local!string:"Advil XX MG/ML Oral Suspension", find(regexfirstmatch("[0-9]",local!string),local!string) )
...results in:
Yes, In that case null check can be applied,
a!localVariables( local!string: "Advil xx MG/ML Oral Suspension", if( a!isNullOrEmpty(regexfirstmatch("[0-9]", local!string)), "", find( regexfirstmatch("[0-9]", local!string), local!string ) ) )
I got 7 as result?
Thanks! This is the one I went with. Works great, I appreciate the help!
Unknown said:I got 7 as result?
Seems correct to me (?)
hahahaha made my day.but the target was to get the number itself, if I got it right?
Unknown said:get the number itself
Oh - I was thinking of the OP's question which was, "What I'm wondering is how do I get the index of the first character that's a number?", which is what the above is.