Thursday, September 25, 2008

First Win at DST

Hello all,

Today was a very good day for me at DST. I owe it to Steve Brown for making me learn regular expressions 10 years ago. Today my team was presented with this problem: How to identify multiple spaces in a line an outside source and get it to be formatted in a standard format. The original technique used multiple if/then/else scenarios and then looping through each line to insure its format. I was overheard the discussion next to me and offered the suggestion of using a regular expression to identify the pattern of more than one space between words and then replace all subsequent spaces with nothing. After two minutes of tweaking the javascript, it was working and it works fast! The page originally loaded in ten seconds. It now loads without delay. Thank you Mr. Brown. I finally have a feather in my hat at DST.

Here is the line:

s/\s{2.}\ \g

This is read:

Substitute white space of two or more to infinity with a single space globally on the line.

-Andy

0 Comments:

Post a Comment

<< Home