Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Regex Lab

Experiments in regex creation

To Regex or not to Regex

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]*$) 

Sponsor
Published Monday, December 18, 2006 10:00 AM by wskanaan

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

wskanaan said:

Note:

The patterns extract some extra text characters depending on the positions of the target sting

December 18, 2006 11:32 AM
 

Stevezilla00 said:

I would add the following to your conclusion: "Unless you deeply understand regex performance issues." If you do understand such things, you can usually write a better regex, and you're likely to know in advance which approach will be faster anyway. Too many programmers complain about regular expression performance when the real issue is they do not know how to write a performance-optimized regex.
June 5, 2007 12:26 PM
 

wskanaan said:

I have to agree... I use regex for things that require little processing... things like form validation. For things that require a lot of precessing I tend to try to find other ways...

June 5, 2007 12:47 PM

Leave a Comment

(required) 
(optional)
(required) 
Enter the code you see below

Submit

This Blog

Syndication

Tags

No tags have been created or used yet.