博文
Javascript 正则表达式(2009-11-17 19:28:00)
摘要:一, 贪心与非贪心
var reg = /c{1,}/;var str='cccccTest';reg.exec(str);
可以看到返回结果为"ccccc",说明正则表达式会尽量多的匹配。
如果我们希望正则尽量少地匹配字符,那么就可以在表示数字的符号后面加上一个?。组成如下的形式:
{n,}?, {m,n}?
同样来看一个例子:
var reg = /c{1,}?/;var str='ccccc';
可以看到返回结果只有一个c,尽管有5个c可以匹配,但是由于正则表达式是非贪心模式,所以只会匹配一个。
......
Javascript String(2009-11-17 19:17:00)
摘要:Javascript String
1. search()
var test = "what is happening here";var result = test.search("is");
结果"result = 5"
search()方法返回substring的index,如果没有找到,则返回-1
2. replace()
var myVar = "Hello there";var newvar = myVar.replace("e", "E");
结果newVar为"HEllo there".
注意: myVar的值不会被改变; 替换的时候只会替换到第一个匹配的值。如果想要全部替换,可以使用正则表达式。
3.格式化strings
• big: Returns the string in big tags
• blink: Returns the string in blink tags
• bold: Returns the string in b tags
• fixed: Returns the string in tt tags (for fixed-width display)
• fontcolor: Returns the string in font tags with the color attribute set to the color you specify as an argument
• fontsize: Returns the string in font tags with the size attribute set to the size you specify as an argument
• italics: Returns the string in i tags
• small: Returns the string in small tags
• strike: Returns the string in strike tags (for a strikethrougheffect)
• sub: Returns the string in......
typeof 运算符(2009-11-17 18:39:00)
摘要:typeof 运算符
typeof 运算符返回一个用来表示表达式的数据类型的字符串。 可能的字符串有:"number"、"string"、"boolean"、"object"、"function" 和 "undefined"。 如: alert(typeof (123));//typeof(123)返回"number" alert(typeof ("123"));//typeof("123")返回"string" ......
