Highlighted

RegExp question again (but w/ different beat)

Explorer ,
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

245

Likes

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

RegExp question again (but w/ different beat)

Explorer ,
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

246

Likes

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
Dec 27, 2016 0
BKBK LATEST
Adobe Community Professional ,
Dec 28, 2016

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>

Likes

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
Reply
Loading...
Dec 28, 2016 0