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

Regex to find word

Contributor ,
Nov 15, 2012 Nov 15, 2012

Copy link to clipboard

Copied

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

Views

804

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

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>

Votes

Translate

Translate
LEGEND ,
Nov 15, 2012 Nov 15, 2012

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

^_^

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

LATEST

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

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