Copy link to clipboard
Copied
Hope we have some true regexp guru here...
Here's a question. I have the following list.
list = "id,option9,option10,option11,option12,option13,option14,option15,orderno,option10txt,option11txt,option16"
and I have a term called "optoin16", which does not match any exact item or element in the list, however, in this case,
the last item, namely, option16, is the closest match, that is what I want.
How do we construct a regular expression to find "option16" from this list based on "optoin16"?
Thanks.
Copy link to clipboard
Copied
You could match on indices (digits), like this
<cfset matches = "">
<cfset item="optoin16">
<cfset list = "id,option9,option10,option11,option12,option13,option14,option15,orderno,option10txt,option11txt,option16,option16blablabla">
<cfset arrayItemIndex = reMatch("[\d]+",item)>
<cfloop list="#list#" index="listElem">
<cfset arrayListElementMatch = reMatch(".*(#arrayItemIndex[1]#).*",listElem)>
<cfif arrayLen(arrayListElementMatch) GT 0>
<cfset matches = listAppend(matches,arrayListElementMatch[1])>
</cfif>
</cfloop>
<cfoutput>#matches#</cfoutput>