| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Regular_expressions/Quantifier | [Back] [Original] |
Get to know MDN better
//
atom?
atom*
atom+
atom{count}
atom{min,}
atom{min,max}
//
atom??
atom*?
atom+?
atom{count}?
atom{min,}?
atom{min,max}?
? |
0 | 1 |
* |
0 | |
+ |
1 | |
{count} |
count |
count |
{min,} |
min |
|
{min,max} |
min |
max |
const re = /a{1, 3}/;
re.test("aa"); // false
re.test("a{1, 3}"); // true
Unicode { }
/a{1, 3}/u; // SyntaxError: Invalid regular expression: Incomplete quantifier
/a{3,2}/; // SyntaxError: Invalid regular expression: numbers out of order in {} quantifier
/[ab]*/.exec("aba"); // ['aba']
?
/a*/.exec("aaa"); // ['aaa'];
/a*?/.exec("aaa"); // [''];
/^a*?$/.exec("aaa"); // ['aaa'];
/a*?$/.exec("aaa"); // ['aaa']; 2
/[ab]+[abc]c/.exec("abbc"); // ['abbc']
[ab]+ "abb" [abc]c ("c") "ab"
/(a*)*/.exec("b")
/(aa|aabaac|ba)*/.exec("aabaac") "aabaac" "aa" :ba"
/^*/; // SyntaxError: Invalid regular expression: nothing to repeat
/(?=a)?b/.test("b"); // true; 0
HTML ?
function stripTags(str) {
return str.replace(/<.+?>/g, "");
}
stripTags("<p><em>lorem</em> <strong>ipsum</strong></p>"); // 'lorem ipsum'
>
function stripTags(str) {
return str.replace(/<[^>]+>/g, "");
}
stripTags("<p><em>lorem</em> <strong>ipsum</strong></p>"); // 'lorem ipsum'
:
> HTML HTML API
Markdown 1 2
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 |