Skip to main content
Inspiring
December 28, 2016
Question

RegExp question again (but w/ different beat)

  • December 28, 2016
  • 1 reply
  • 443 views

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.

This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
December 28, 2016

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>