[thelist] IE RegExp Assistance
Howard Jess
howard at dhitechnologies.com
Fri Dec 16 11:35:17 CST 2005
> Hi all. I'm having an issue with IE and a regular expression to split
> text for a spellchecker. I'm using the expression (\s+) on the sentence
> "This is my sentence." and I get a return of "This, ,is, ,my,
> ,sentence." from Firefox and a return of "This,is,my,sentence." from IE.
> Is there an expression I can use to get IE to keep the spaces?
Assuming your javascript looks something like:
s = "This is my sentence.";
r = s.split(/(\s+)/);
the answer is that IE doesn't properly implement "capturing" regular
expressions in String.split. You can get what you want, however, using
RegExp.exec in a loop.
hj
More information about the thelist
mailing list