• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

18. Regular Expressions in ColdFusion > 18.2. Finding Strings

Finding Strings

To find a string in a block of text, you use the REFind( ) or REFindNoCase( ) functions. REFind( ) and REFindNoCase( ) are used when you want to know the position of the expression being searched for within a string. REFind( ) performs a case-sensitive search; REFindNoCase( ) performs a case-insensitive search. Regardless of the function used, they both use the same syntax:

REFind(RegularExpression, String [, StartPosition] [, ReturnSubExpressions])
REFindNoCase(RegularExpression, String [, StartPosition] [, ReturnSubExpressions])

Both the REFind( ) and REFindNoCase( ) functions accept the same parameters. The following example finds the first occurrence of “tom” regardless of case:

<cfset MyString="This is a red tomato.">
<cfset ThePosition=REFindNoCase("tom", MyString)>
   
<cfoutput>
The Position:  #ThePosition#
</cfoutput>

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint