I came to this site because I was looking for patterns to help me in creating a syntax highliting editor.... I was finding it increasingly difficult to formulate patterns that are effective in meeting every possibility there is....
The first issue I had was performance... by the time I got around to semi-perfecting the initial coloring activity I had to wait about 24 seconds for the function to end... after changing the logic the time went down to about 3 seconds... by the time I finished tuning it I got the script down to less than a second --- about 0.7 seconds...
Then I thought.... why not try not using the regex functions??? Just go through the text letter by letter and color according to the area you are in by keeping track of the tags and punctuations... this way the script loops only once through the text... the result?? the function takes an average of 0.1 seconds to do its work... I still have to manage identifying variables... but that shouldn't add too much time... even when looking through about 3800 function names each time trying to identify one...
The conclusion? use regex in small activities... unless performance is not an issue.
The following are the code patterns I used for c#.net
functions: [{\s\n=\.\(][\\w]+\\s*[\"\\(]
key words: [{\s\n=\.\(][\\s]*[a-zA-Z_]+\s*[\"\(\']?
strings in double quotation marks: [=\.\[,]\s*\"[^\"\n]*\"\s*
strings in single quotation marks:([=\.\[,]\s*)\'[^\']*\';?
comments following //: (^[^\'|\\\.]*)//([^\n]*$)