Skip to main content
Inspiring
November 15, 2012
Answered

Regex to find word

  • November 15, 2012
  • 3 replies
  • 976 views

Anyone know the Regex to find if a variable contains a word eg this var has "Surplus Percentage Total in the Amount of $2000.00"

So I need to know it contains the word 'Percentage'?

Here is my code

cfset xyz='Surplus Percentage Total in the Amount of $2000.00'

cfset foundword= REFind('Percentage', xyz)

The above is not working

    This topic has been closed for replies.
    Correct answer BKBK

    <cfset xyz='Surplus Percentage Total in the Amount of $2000.00'>

    <cfset foundword = REFindNoCase('Percentage',xyz)>

    <cfif foundword GT 0>

    Word found at position <cfoutput>#foundword#</cfoutput>

    <else>

    Word not found

    </cfif>

    3 replies

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    November 15, 2012

    <cfset xyz='Surplus Percentage Total in the Amount of $2000.00'>

    <cfset foundword = REFindNoCase('Percentage',xyz)>

    <cfif foundword GT 0>

    Word found at position <cfoutput>#foundword#</cfoutput>

    <else>

    Word not found

    </cfif>

    umuayoAuthor
    Inspiring
    November 15, 2012

    Thanks.... implemented already with the RefindNocase. The values were coming in either lower/Upper case realized I have to use RefindNocase

    WolfShade
    Legend
    November 15, 2012

    According to the docs, it will not return the subexpression unless you set the returnsubexpression flag to true.  If the flag is false (default), it retuns an array of length and position of the subexpression.

    ^_^

    Inspiring
    November 15, 2012

    The code you displayed might not be the actual code.  Where did those white things come from?