仲颖**6年前
见PPT
将直接量字符单独放进[]中就组成字符类,一个字符类可以匹配它所包含的任意一个字符,[]就是用于查找某个范围内的字符,
Chrome本来就支持多行模式。
一行模式直接按回车就会执行并输出结果。如果多行模式就按shfit+回车键 等你输入完了再回车就行了。希望能帮到你。
总结一句话:shfit+回车键 就是多行js模式
测试:
var str="Hello World! Welcome to php.cn123"
var a=/[0-9]/
var b=/[a-z]/
var c=/[A-Z]/
var d=/[a-zA-Z0-9]/
undefined
a.exec(str)
["1", index: 30, input: "Hello World! Welcome to php.cn123", groups: undefined]
b.exec(str)
["e", index: 1, input: "Hello World! Welcome to php.cn123", groups: undefined]
c.exec(str)
["H", index: 0, input: "Hello World! Welcome to php.cn123", groups: undefined]
d.exec(str)
["H", index: 0, input: "Hello World! Welcome to php.cn123", groups: undefined]
var str1="Hello World! Welcome to php.cn123"
undefined
var aa=/l+/ //全局匹配
undefined
str1.match(aa)
["ll", index: 2, input: "Hello World! Welcome to php.cn123", groups: undefined]
var a1=/l+/g //全局匹配
str1.match(a1)
(3) ["ll", "l", "l"]
var b1=/\w/g //全局匹配
str1.match(b1)
(27) ["H", "e", "l", "l", "o", "W", "o", "r", "l", "d", "W", "e", "l", "c", "o", "m", "e", "t", "o", "p", "h", "p", "c", "n", "1", "2", "3"]
var b1=/\w+/g //全局匹配
str1.match(b1)
(6) ["Hello", "World", "Welcome", "to", "php", "cn123"]
var c1=/lo*/g
str1.match(c1)
(4) ["l", "lo", "l", "l"]
var c1=/lo?/g
str1.match(c1)
(4) ["l", "lo", "l", "l"]
var st="1000 100 1234 12 5000"
var b=/\d{4}/ //查找4位数的数字
undefined
var st="1000 100 1234 12 5000"
var b=/\d{4}/g //查找4位数的数字
st.match(b)
(3) ["1000", "1234", "5000"]
var st="1000 100 1234 12 5000"
var b=/\d{3,4}/g //查找4位数的数字
st.match(b)
(4) ["1000", "100", "1234", "5000"]
var st="1000 100 1234 12 5000 456 7 23 899"
var b=/\d{3,}/g //查找至少是3位数的数字
st.match(b)
(6) ["1000", "100", "1234", "5000", "456", "899"]
var str="Isthisallthereis"
var a=/is(?=all)/g
str.match(a)
["is"]
var str="Isthisallthereis"
var a=/is(?!all)/g //注意,这里返回的是thereis的is
str.match(a)
["is"]
var str="Isthisallthereis"
var b=/is(?!all)/g //注意,这里返回的是thereis的is
str.match(b)
["is"]
str.search(b)
14
var str="Isthisallthereis"
var a=/is(?=all)/g
str.match(a)
["is"]
str.search(a)
4
0