Regular expressions

Regular expressions are a powerful tool for examining and modifying text. Regular expressions themselves, with a general pattern notation almost like a mini programming language, allow you to describe and parse text. They enable you to search for patterns within a string, extracting matches flexibly and precisely. However, you should note that because regular expressions are more powerful, they are also slower than the more basic string functions. You should only use regular expressions if you have a particular need.

 

  • Match integer and decimal numbers.
    [0-9]+(?:\.[0-9]*)?
  • Matches center or centre.
    cent(er|re)
  • Simplified example of matching HTML tags.
    <[^<]+?>
  • Simplified example of matching text that is not part of a HTML tag.
    (?<=^|>)[^><]+?(?=<|$)
  • Looks for the URL string starting with http://
    (((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)
  • Removes all the blank characters in a String (spaces, tabs, return....)
    [ \t\r\n\v\f]
  • Get TR in a TABLE
    <td.*?>(.*?)</td>
  • Matches strings with letters AND numbers
    [a-z0-9][a-z]+[0-9]+
  • Verify That Strings Are in Valid E-Mail Format
    ^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$ OR
    ([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})
  • Strips invalid non-alphanumeric characters from a string
    [^\w\.@-]
  • Searches an input string and prints out all the href="…" values and their locations in the string
    href\s*=\s*(?:"(?<1>[^""]*)"|(?<1>\S+))
  • IP Address Regexp
    \b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
  • Float Number Regexp
    [-+]?(?:\b[0-9]+(?:\.[0-9]*)?|\.[0-9]+\b)(?:[eE][-+]?[0-9]+\b)?
  • Date in format yyyy-mm-dd
    (19|20)\d\d([- /.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])
  • Matching Numeric Ranges (for example 0 or 000 to 255)
    ^([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$
  • Finding or Verifying Credit Card Numbers
    Visa: ^4[0-9]{12}(?:[0-9]{3})?$
    MasterCard: ^5[1-5][0-9]{14}$
    American Express: ^3[47][0-9]{13}$
    Diners Club: ^3(?:0[0-5]|[68][0-9])[0-9]{11}$
    Discover: ^6(?:011|5[0-9]{2})[0-9]{12}$
    JCB: ^(?:2131|1800|35\d{3})\d{11}$
  • Trim a string
    ^(\s*)([\W\w]*)(\b\s*$)
  • Dollor amount
    ^\$?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$
  • Find file extension
    (?<=\.)([^\.]+)$
  • Clean all whitespaces of a some string.
    \s
  • Get <script> tag content
    <[^>]*?script.*?>[^<]*]*?script.*?>

 

 

Small fish in the sea

A ColdFusion programer since 2006 which have developed various web based applications using Adobe ColdFusion (from version 4.5 to 9).

manoj_kothari9@yahoo.com
+91 9711601778

Join me on:

more about me

Video times

Here are some videos related to ColdFusion, Database tutorials. Hopefully it will be helpful for you.

view videos

Tip for the day

Use ListAppend() instead of string concatenate

Suppose we have a list i.e "one,two,three" and want to add another text "four", you can use ListAppend() of coldFusion.

view detail

Guest book
Adobe ColdFusion 9