[icoFolderApps.png]Program files
[icoHelp.png] Help[icoRegExp.png] Regular expressions
 Regular expressions (9oct2010)
Just one thing: learn regular expressions magic. With their power in your hands you can elaborate text streams, parse data, validate user input and so on.

You'll find them everywhere: in your preferred editor search/replace functions or as library in your scripting environment or compiled language. Their syntax is cryptic and concise and at first you'll find hard to decipher long expressions. My advice is to start gradually following few of the billions tutorials available on the net.

I'll put here some examples, Note: regular expression strings are usually indicated by putting them inside / characters; you can test them assigning directly these strings in javascript to a RegExp object; you can also test them with minor changes in your editor (try PSPad) search/replace dialog.
  • Replace date format, find occurrences like 25.12.2007 and transform them to 2007-12-25:
    search: /\b(\d{2})\.(\d{2})\.(\d{4})\b/
    replace: /$3-$2-$1/
  • Find Siax PLC register names like VB1003, Vq1, vn256 and so on:
    search: /\b[Vv][QqNnBb]\d{1,4}\b/
    or with a case insensitive search: /\bv[qnb]\d{1,4}\b/i
  • Retrieve the value assigned to an identifier like 44 in Val1 = 44:
    get capture $1 in: /\b[_a-zA-Z]\w*\s*=\s*(\d+)/
 some notes.txt
a(?=b) positive lookahead a(?!b) negative lookahead (?<=a)b positive lookbehind (!) (?<!a)b negative lookbehind (!) Some regular expression examples <[^<>]+> a xml tag //.*$ an entire line starting with '//' \*.*?\* a c-style multi-line comment "[^"\r\n]*" a single-line quoted string without inner quote character "[^"\\\r\n]*(?:\\.[^"\\\r\n]*)*" a single-line quoted string with escaped quote character "[^"\\]*(?:\\.[^"\\]*)*" a multiple lines quoted string \d+ a positive integer number [-+]?\b\d+\b an integer number with sign 0[xX][0-9a-fA-F]+ a c-style hexadecimal number (([0-9]+)?\.)?[0-9]+ a floating point number with optional integer part ([0-9]+\.([0-9]+)?|\.[0-9]+) a (strict) floating point number (([0-9]+)?\.)?[0-9]+([eE][-+]?[0-9]+)? a number in scientific notation (key1|key2|key3|...) a set of keywords