+
查找一个或多个字符,使用星号*
查找零个或多个字符。这些都很方便,但有时需要匹配一定范围的匹配模式。
可以使用数量说明符
指定匹配模式的上下限。数量说明符与花括号({
和}
)一起使用。可以在花括号之间放两个数字,这两个数字代表匹配模式的上限和下限。
例如,要在字符串"ah"
中匹配仅出现3
到5
次的字母a
,正则表达式应为/a{3,5}h/
。
```js
let A4 = "aaaah";
let A2 = "aah";
let multipleA = /a{3,5}h/;
multipleA.test(A4); // Returns true
multipleA.test(A2); // Returns false
```
ohRegex
以匹配在"Oh no"
中仅出现3
到6
次的字母h
。
'Ohh no'
。"
testString: assert(!ohRegex.test("Ohh no"));
- text: "你的正则表达式应该匹配'Ohhh no'
。"
testString: assert("Ohhh no".match(ohRegex)[0].length === 7);
- text: 正则表达式应该匹配 "Ohhhh no"
。
testString: assert("Ohhhh no".match(ohRegex)[0].length === 8);
- text: "你的正则表达式应该匹配'Ohhhhh no'
。"
testString: assert("Ohhhhh no".match(ohRegex)[0].length === 9);
- text: "你的正则表达式应该匹配'Ohhhhhh no'
。"
testString: assert("Ohhhhhh no".match(ohRegex)[0].length === 10);
- text: "你的正则表达式不应该匹配'Ohhhhhhh no'
。"
testString: assert(!ohRegex.test("Ohhhhhhh no"));
```