1、以xx开头,以xx结尾
如:
(1) 左侧空白符,即以空白符开头—— /^\s/
(2) 右侧空白符,即以空白符结尾—— /\s+$/
空白符:\s
以xx开头:^ // ^n,n为要开头的字符
以xx结尾:$ // n$,n为要结尾的字符
以空白符开头:^\s
以空白符结尾:\s$
至少包含一个:n+ // n为要包含的字符
至少包含一个空白符开头:^\s+
至少包含一个空白符结尾:\s+$
全局匹配:str.replace(/^\s+/g,"subStrNew") , str.replace(/\s+$/g,"subStrNew")
(3)查找数字
数字:\d
查找以..开头:^
查找以数字开头:^\d
包含x或y个:{x,y}
2、javascript replace()方法
replace()方法用于在字符串中用一些字符替换另一些字符,或替换一个与正则表达式匹配的子串。
stringObject.replace(regexp/substr,replacement);
eg:
(1)
str =" helloworld"
str.replace(/hello/,"World"); // 用World 替换 str字符串中的hello