[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Regular_expressions/Quantifier [Back]  [Original]

: *, +, ?, {n}, {n,}, {n,m} - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

: *, +, ?, {n}, {n,}, {n,m}

Baseline

20157

regex
// 
atom?
atom*
atom+
atom{count}
atom{min,}
atom{min,max}

// 
atom??
atom*?
atom+?
atom{count}?
atom{min,}?
atom{min,max}?

atom

count

min

max

? 0 1
* 0
+ 1
{count} count count
{min,} min
{min,max} min max

{count}{min,}{min,max}

js
const re = /a{1, 3}/;
re.test("aa"); // false
re.test("a{1, 3}"); // true

Unicode { }

js
/a{1, 3}/u; // SyntaxError: Invalid regular expression: Incomplete quantifier

js
/a{3,2}/; // SyntaxError: Invalid regular expression: numbers out of order in {} quantifier

js
/[ab]*/.exec("aba"); // ['aba']

?

js
/a*/.exec("aaa"); // ['aaa']; 
/a*?/.exec("aaa"); // ['']; 
/^a*?$/.exec("aaa"); // ['aaa']; 

js
/a*?$/.exec("aaa"); // ['aaa'];  2 

js
/[ab]+[abc]c/.exec("abbc"); // ['abbc']

[ab]+ "abb" [abc]c ("c") "ab"

/(a*)*/.exec("b")

/(aa|aabaac|ba)*/.exec("aabaac") "aabaac" "aa" :ba"

js
/^*/; // SyntaxError: Invalid regular expression: nothing to repeat

Unicode

js
/(?=a)?b/.test("b"); // true;  0 

HTML

HTML ?

js
function stripTags(str) {
  return str.replace(/<.+?>/g, "");
}

stripTags("<p><em>lorem</em> <strong>ipsum</strong></p>"); // 'lorem ipsum'

>

js
function stripTags(str) {
  return str.replace(/<[^>]+>/g, "");
}

stripTags("<p><em>lorem</em> <strong>ipsum</strong></p>"); // 'lorem ipsum'

: > HTML HTML API

Markdown

Markdown 1 2

js
function countParagraphs(str) {
  return str.match(/(?:\r?\n){2,}/g).length + 1;
}

countParagraphs(`
Paragraph 1

Paragraph 2
Containing some line breaks, but still the same paragraph

Another paragraph
`); // 3

: Markdown Markdown

ECMAScript 2027 LanguageSpecification
# prod-Quantifier


Web Proxy Viewer  |  New URL  |  Original Page