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

Regex to find word

Contributor ,
Nov 15, 2012 Nov 15, 2012

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

887
Translate
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

correct answers 1 Correct answer

Community Expert , Nov 15, 2012 Nov 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>

Translate
LEGEND ,
Nov 15, 2012 Nov 15, 2012

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

Translate
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
LEGEND ,
Nov 15, 2012 Nov 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.

^_^

Translate
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 ,
Nov 15, 2012 Nov 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>

Translate
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
Contributor ,
Nov 15, 2012 Nov 15, 2012
LATEST

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

Translate
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