Reg Exp: Newbie Question
Sorry, a newbie question here:
I encountered the following code:
var temp = somestring;
temp = temp.replace( /^\s*/, "" );
temp = temp.substring(0,6);
Doesn't this mean replace zero or more occurrences of non-whitespace with the empty string?
If so, I don't see how the 3rd line of code will ever return anything but whitespace. Am I off the mark?
That's something confusing with regExps, the carat can either represent the start of a line(or in multiline mode the start of the whole string) OR mean not.
In general if it comes first it means the former, if it occurs later on it means the later, but there are several complex rules that define this.
I read up on it - it seems that the big difference is whether the caret is used inside square brackets or outside. Inside it negates the character class. Outside it marks the beginning of the string. So in my example the expression means "trim all whitespace from the beginning of the line".