regarding string expressions..
any body can tell me the string processing in the following lines..
i am not able to get what is there inside it..
this java script code purpose is to remove the leadning and trailing spaces.
please let me know what is happening there..
var x=this;
x=x.replace(/^\s*(.*)/, "$1");
x=x.replace(/(.*?)\s*$/, "$1");
return x;
[376 byte] By [
mahanare] at [2007-11-18 16:35:41]

# 1 Re: regarding string expressions..
x=x.replace(/^\s*(.*)/, "$1");
The first argument of the replace function, is a regular expression, that is to be matched against the object string, and replaced by the second argument. The / characters marks the beginning and end of the regular expression, ^ matches the beginning of a string, \s matches any kind of white space character (space, tab and newline), * means that the previous expression (\s in this case) should be repeated any number of times. The ( ) parenthesis encloses a expression and implicitly declares the variable $1 to contain whatever the expression matches. Using multiple ( ) parenthesis in an expression will declare consecutive variables $1, $2, $3 and so on. The contents of the parenthesis (.*) matches any string of charactes. Dot . means any charactes and again * means repeat any number of times.
If you want lean more about this try doing some googeling. Or read the the what the javascript references say about regular expressions http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/regexp.html#1193136
khp at 2007-11-8 0:18:58 >

# 2 Re: regarding string expressions..
Thank you very much for the reply. i understood it now.
(i forgot to reply, i have seen reply immediately u posted on this forum)