+来查找一个或多个字符,使用星号*来查找零个或多个字符。这些很方便,但有时你想要匹配一定范围的模式。您可以使用quantity specifiers模式的下限和上限。数量说明符与大括号( {和} )一起使用。您在大括号之间放置了两个数字 - 用于较低和较高的模式数。例如,为了匹配字母"ah"出现3到5次的字母a ,你的正则表达式将是/a{3,5}h/ 。 让A4 =“aaaah”;
让A2 =“aah”;
令multipleA = / a {3,5} h /;
multipleA.test(A4); //返回true
multipleA.test(A2); //返回false
ohRegex以匹配单词"Oh no"中的3到6字母h 。 "Ohh no"
testString: 'assert(!ohRegex.test("Ohh no"), "Your regex should not match "Ohh no"");'
- text: 你的正则表达式应该匹配"Ohhh no"
testString: 'assert(ohRegex.test("Ohhh no"), "Your regex should match "Ohhh no"");'
- text: 你的正则表达式应该匹配"Ohhhh no"
testString: 'assert(ohRegex.test("Ohhhh no"), "Your regex should match "Ohhhh no"");'
- text: 你的正则表达式应该匹配"Ohhhhh no"
testString: 'assert(ohRegex.test("Ohhhhh no"), "Your regex should match "Ohhhhh no"");'
- text: 你的正则表达式应该匹配"Ohhhhhh no"
testString: 'assert(ohRegex.test("Ohhhhhh no"), "Your regex should match "Ohhhhhh no"");'
- text: 你的正则表达式不应该匹配"Ohhhhhhh no"
testString: 'assert(!ohRegex.test("Ohhhhhhh no"), "Your regex should not match "Ohhhhhhh no"");'
```