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

18. Regular Expressions in ColdFusion > 18.5. Useful Regular Expressions

Useful Regular Expressions

Now that you have a better idea of how regular expressions work, let’s take a look at how you can actually use them in your own ColdFusion applications. Here are some regular expressions that perform common search-and-replace tasks:

  • Replace all characters in a string that aren’t numbers, letters, or underscores with an underscore:

    <cfset NewString = REReplaceNoCase("This is a test", "\W", "_", 
           "All")>
  • Replace all spaces in a filename with the underscore character; this is useful in situations where you allow users to upload files to your ColdFusion server via their web browsers:

    <cfset NewFilename = REReplace("My File Name.txt", " ", "_", "All")>
  • Return the full directory path from a string containing a full path including filename:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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