• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

RegExp question again (but w/ different beat)

Explorer ,
Dec 27, 2016 Dec 27, 2016

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.

TOPICS
Advanced techniques

Views

312

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 28, 2016 Dec 28, 2016

Copy link to clipboard

Copied

LATEST

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation