{"id":3337,"date":"2022-08-08T19:27:32","date_gmt":"2022-08-08T10:27:32","guid":{"rendered":"https:\/\/weseek.co.jp\/tech\/?p=3337"},"modified":"2023-04-17T10:50:17","modified_gmt":"2023-04-17T01:50:17","slug":"%e3%80%90javascript%e3%80%91%e6%ad%a3%e8%a6%8f%e8%a1%a8%e7%8f%be%e3%83%aa%e3%83%86%e3%83%a9%e3%83%ab%e3%81%a8-regexp-%e3%82%af%e3%83%a9%e3%82%b9","status":"publish","type":"post","link":"https:\/\/weseek.co.jp\/tech\/3337\/","title":{"rendered":"\u3010JavaScript\u3011\u6b63\u898f\u8868\u73fe\u30ea\u30c6\u30e9\u30eb\u3068 RegExp \u30af\u30e9\u30b9"},"content":{"rendered":"<p>\u7686\u3055\u3093\u3053\u3093\u306b\u3061\u306f\uff01WESEEK \u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u30a8\u30f3\u30b8\u30cb\u30a2\u306e <a href=\"https:\/\/twitter.com\/TaichiMasuyama\">\u5897\u5c71<\/a> \u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u30d6\u30e9\u30a6\u30b6\u4e0a\u3067\u5b9f\u884c\u3055\u308c\u308b JavaScript \u306e\u6b63\u898f\u8868\u73fe\u304c\u30c6\u30fc\u30de\u3067\u3059\u3002\u6b63\u898f\u8868\u73fe\u30ea\u30c6\u30e9\u30eb\u3068 RegExp \u30af\u30e9\u30b9\u306f\u4f55\u304c\u9055\u3046\u306e\u304b\u3001\u3069\u3093\u306a\u30e1\u30ea\u30c3\u30c8\u30c7\u30e1\u30ea\u30c3\u30c8\u304c\u3042\u308b\u306e\u304b\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002\u307e\u305f\u3001\u30d6\u30e9\u30a6\u30b6\u4e0a\u3067\u5b9f\u884c\u3059\u308b\u969b\u306e\u6ce8\u610f\u70b9\u306b\u3064\u3044\u3066\u3082\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<h1>\u76ee\u6b21<\/h1>\n\n<h1>\u306f\u3058\u3081\u306b<\/h1>\n<p>JavaScript \u306e\u5b9f\u884c\u74b0\u5883\u306f\u4e3b\u306b\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u3067\u4f7f\u308f\u308c\u308b <a href=\"https:\/\/nodejs.dev\/\">Node.js<\/a> \u3060\u3063\u305f\u308a\u3001\u30d6\u30e9\u30a6\u30b6\u3067\u4f7f\u308f\u308c\u308b Chrome \u306e <a href=\"https:\/\/v8.dev\/\">v8 engine<\/a> \u3084 Safari \u306e <a href=\"https:\/\/developer.apple.com\/documentation\/javascriptcore\">JavaScriptCore<\/a> \u306a\u3069\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u30a6\u30a7\u30d6\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u958b\u767a\u3057\u3066\u3044\u308b\u3068\u7279\u306b\u30d6\u30e9\u30a6\u30b6\u74b0\u5883\u306e\u5dee\u7570\u306b\u3088\u3063\u3066 Chrome \u3067\u306f\u52d5\u304f\u3051\u3069 Safari \u3067\u306f\u52d5\u304b\u306a\u3044\uff01\u306a\u3093\u3066\u5834\u9762\u306b\u906d\u9047\u3059\u308b\u3053\u3068\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u6b63\u898f\u8868\u73fe\u3082\u3001\u30d6\u30e9\u30a6\u30b6\u306e\u5f71\u97ff\u3092\u53d7\u3051\u308b\u8981\u56e0\u306e\u4e00\u3064\u3067\u3059\u3002\u4eca\u56de\u306f\u3001JavaScript \u306e\u6b63\u898f\u8868\u73fe\u3092\u30d6\u30e9\u30a6\u30b6\u3067\u4f7f\u3046\u3068\u304d\u306b\u7b46\u8005\u306e <a href=\"https:\/\/twitter.com\/TaichiMasuyama\">\u5897\u5c71<\/a> \u304c\u8003\u3048\u3066\u3044\u308b\u3053\u3068\u3001\u6c17\u3092\u3064\u3051\u3066\u3044\u308b\u3053\u3068\u3092\u542b\u3081\u3066\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u8a18\u4e8b\u306e\u6700\u5f8c\u306b\u306f <a href=\"https:\/\/github.com\/weseek\/growi\">GROWI<\/a> \u3067\u5b9f\u969b\u306b\u884c\u308f\u308c\u3066\u3044\u308b\u5bfe\u7b56\u306b\u3064\u3044\u3066\u3082\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h1>JavaScript \u3067\u6b63\u898f\u8868\u73fe\u3092\u6271\u3046<\/h1>\n<p>JavaScript \u3067\u6b63\u898f\u8868\u73fe\u3092\u5229\u7528\u3059\u308b\u65b9\u6cd5\u306f\u4e3b\u306b2\u7a2e\u985e\u3042\u308a\u307e\u3059\u3002<\/p>\n<h2>\u6b63\u898f\u8868\u73fe\u30ea\u30c6\u30e9\u30eb<\/h2>\n<p>\u6b63\u898f\u8868\u73fe\u30ea\u30c6\u30e9\u30eb\u306f JavaScript \u306e\u69cb\u6587\u3068\u3057\u3066\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u66f8\u304d\u65b9\u3067\u3059\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304f\u3053\u3068\u3067 RegExp \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u540c\u7b49\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u3057\u3066\u6271\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-js\">const regexp = \/^START[1-9]{1,3}END$\/;\n\nconsole.log(regexp.test(&#039;START123END&#039;));\n\/\/ true<\/code><\/pre>\n<h2>RegExp \u30af\u30e9\u30b9<\/h2>\n<p>RegExp \u30af\u30e9\u30b9\u306f JavaScript \u304c\u6a19\u6e96\u3067\u7528\u610f\u3057\u3066\u3044\u308b\u6b63\u898f\u8868\u73fe\u3092\u6271\u3046\u305f\u3081\u306e\u30af\u30e9\u30b9\u3067\u3059\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u521d\u671f\u5316\u3057\u3066\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-js\">const regexp = new RegExp(&#039;^START[1-9]{1,3}END$&#039;);\nconsole.log(regexp.test(&#039;START1234END&#039;));\n\/\/ false<\/code><\/pre>\n<h1>\u30e1\u30ea\u30c3\u30c8\u30c7\u30e1\u30ea\u30c3\u30c8\u6bd4\u8f03<\/h1>\n<p>\u6b63\u898f\u8868\u73fe\u30ea\u30c6\u30e9\u30eb\u3068 RegExp \u30af\u30e9\u30b9\u3092\u6bd4\u8f03\u3057\u307e\u3059\u3002<\/p>\n<h2>RegExp \u306f\u52d5\u7684\u306b\u5909\u66f4\u53ef\u80fd<\/h2>\n<p>RegExp \u30af\u30e9\u30b9\u306f\u521d\u671f\u5316\u306e\u3068\u304d\u306b\u6b63\u898f\u8868\u73fe\u3092\u6587\u5b57\u5217\u3068\u3057\u3066\u6e21\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u3053\u3067\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30ea\u30c6\u30e9\u30eb\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u52d5\u7684\u306b\u6b63\u898f\u8868\u73fe\u3092\u5909\u3048\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u4e00\u65b9\u3067\u6b63\u898f\u8868\u73fe\u30ea\u30c6\u30e9\u30eb\u3067\u306f\u5024\u3092\u52d5\u7684\u306b\u5909\u66f4\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<pre><code class=\"language-js\">let userInput = &#039;\u5165\u529b&#039;;\n\nconst regexp = new RegExp(`^START${userInput}END$`);<\/code><\/pre>\n<h2>\u6b63\u898f\u8868\u73fe\u30ea\u30c6\u30e9\u30eb\u306f\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u826f<\/h2>\n<p>\u6b63\u898f\u8868\u73fe\u30ea\u30c6\u30e9\u30eb\u3067\u5b9a\u7fa9\u3057\u305f\u6b63\u898f\u8868\u73fe\u306f\u30d6\u30e9\u30a6\u30b6\u3067 JavaScript \u304c\u30ed\u30fc\u30c9\u3055\u308c\u308b\u969b\u306e\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u540c\u6642\u306b\u30b3\u30f3\u30d1\u30a4\u30eb\u3055\u308c\u307e\u3059\u3002\u9006\u306b RegExp \u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3057\u305f\u5834\u5408\u306f RegExp \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u521d\u671f\u5316\u6642\u306b\u6b63\u898f\u8868\u73fe\u304c\u30b3\u30f3\u30d1\u30a4\u30eb\u3055\u308c\u308b\u305f\u3081\u3001\u521d\u671f\u5316\u3057\u3066\u5b9f\u884c\u3059\u308b\u307e\u3067\u306b\u30b3\u30f3\u30d1\u30a4\u30eb\u5206\u306e\u9045\u5ef6\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<p>\u3088\u3063\u3066\u3001\u52d5\u7684\u306b\u5024\u3092\u5909\u66f4\u3057\u306a\u3044\u5834\u5408\u306f\u6b63\u898f\u8868\u73fe\u30ea\u30c6\u30e9\u30eb\u3092\u4f7f\u3046\u307b\u3046\u304c\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u826f\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>\u6ce8\u610f\u70b9<\/h3>\n<p>\u6b63\u898f\u8868\u73fe\u30ea\u30c6\u30e9\u30eb\u304c JavaScript \u30ed\u30fc\u30c9\u6642\u306b\u30b3\u30f3\u30d1\u30a4\u30eb\u3055\u308c\u308b\u306e\u306b\u306f\u30c7\u30e1\u30ea\u30c3\u30c8\u3082\u5b58\u5728\u3057\u307e\u3059\u3002\u6b63\u898f\u8868\u73fe\u306e\u6587\u6cd5\u304c\u9593\u9055\u3063\u3066\u3044\u305f\u308a\u3001\u30d6\u30e9\u30a6\u30b6\u304c\u305d\u306e\u6b63\u898f\u8868\u73fe\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044\u306a\u304b\u3063\u305f\u308a\u3059\u308b\u5834\u5408\u306f\u30b3\u30f3\u30d1\u30a4\u30eb\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002\u3053\u308c\u306f JavaScript \u5b9f\u884c\u524d\u306b\u767a\u751f\u3059\u308b\u306e\u3067\u3001\u5b9f\u884c\u4e2d\u306e\u4f8b\u5916\u51e6\u7406\u306a\u3069\u3067\u5bfe\u51e6\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>\u5b9f\u969b\u306b\u6b63\u898f\u8868\u73fe\u30ea\u30c6\u30e9\u30eb\u3092\u4f7f\u7528\u3059\u308b\u969b\u306b\u306f\u3001\u5229\u7528\u304c\u60f3\u5b9a\u3055\u308c\u3066\u3044\u308b\u30d6\u30e9\u30a6\u30b6\u3067\u4e00\u5ea6\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u306a\u3044\u3053\u3068\u3092\u78ba\u304b\u3081\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002\u7d9a\u3051\u3066 <a href=\"https:\/\/github.com\/weseek\/growi\/\">GROWI<\/a> \u306e\u958b\u767a\u3067\u884c\u308f\u308c\u3066\u3044\u308b\u5bfe\u7b56\u306b\u3064\u3044\u3066\u3082\u307f\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h1>GROWI \u3067\u3084\u3063\u3066\u308b\u3053\u3068<\/h1>\n<p>\u6b63\u898f\u8868\u73fe\u306e\u4e00\u3064\u3067\u3042\u308b <a href=\"https:\/\/www.javadrive.jp\/regex-basic\/writing\/index2.html\">\u5f8c\u8aad\u307f<\/a> \u306f Safari ~v15.6 \u3067\u306f\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u306a\u3044\u305f\u3081\u3001\u6b63\u898f\u8868\u73fe\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u305f\u3068\u304d\u306b\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002\u3088\u3063\u3066\u6b63\u898f\u8868\u73fe\u30ea\u30c6\u30e9\u30eb\u306e\u4ee3\u308f\u308a\u306b RegExp \u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3057\u3066\u3001\u305d\u306e\u521d\u671f\u5316\u51e6\u7406\u3092 try-catch \u3067\u56f2\u3093\u3067\u4f8b\u5916\u51e6\u7406\u3092\u5b9f\u65bd\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-js\">\/\/ \u5b89\u5168\u306a\u6b63\u898f\u8868\u73fe\nlet PATTERN_DEFAULT = \/^((.*)\\\/)?(.+)$\/;https:\/\/regex101.com\/r\/jpZwIe\/1\ntry {\n  \/\/ \u5f8c\u8aad\u307f\u3092\u542b\u3080\u6b63\u898f\u8868\u73fe\n  PATTERN_DEFAULT = new RegExp(&#039;^((.*)(?&lt;!&lt;)\\\\\/)?(.+)$&#039;); \/\/ https:\/\/regex101.com\/r\/HJNvMW\/1\n}\ncatch (err) {\n  \/\/ \u4f8b\u5916\u51e6\u7406\n}<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/weseek\/growi\/blob\/92c06cf743a620aa4425e6f14edab31d9e6139e7\/packages\/core\/src\/models\/devided-page-path.js#L35-L50\">GROWI \u306e\u5b9f\u969b\u306e\u30b3\u30fc\u30c9<\/a> <\/p>\n<p>\u3053\u308c\u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u6b63\u5e38\u306b\u5b9f\u884c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3055\u3089\u306b <a href=\"https:\/\/github.com\/weseek\/growi\/\">GROWI<\/a> \u3067\u306f\u3001\u958b\u767a\u4e2d\u306b\u9593\u9055\u3048\u3066\u5371\u967a\u306a\u6b63\u898f\u8868\u73fe\u3092\u6df7\u5408\u3055\u305b\u3066\u3057\u307e\u308f\u306a\u3044\u69d8\u306b <a href=\"https:\/\/github.com\/weseek\/growi\/blob\/92c06cf743a620aa4425e6f14edab31d9e6139e7\/.eslintrc.js#L61-L69\">eslint \u3092\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059<\/a> \u3002<br \/>\n\u3053\u308c\u3067\u5f8c\u8aad\u307f\u3092\u542b\u3080\u6b63\u898f\u8868\u73fe\u3092\u8a18\u8ff0\u3057\u305f\u5834\u5408\u306f lint error \u304c\u51fa\u3066\u304f\u308c\u308b\u306e\u3067\u3001\u6c17\u3065\u3044\u3066\u305d\u306e\u5834\u3067\u4fee\u6b63\u3067\u304d\u307e\u3059\u3002<\/p>\n<h1>\u307e\u3068\u3081<\/h1>\n<p>\u4eca\u56de\u306f JavaScript \u306e\u6b63\u898f\u8868\u73fe\u3067\u6b63\u898f\u8868\u73fe\u30ea\u30c6\u30e9\u30eb\u3068 RegExp \u30af\u30e9\u30b9\u3092\u4f7f\u3046\u3068\u304d\u306e\u9055\u3044\u3084\u3001\u30d6\u30e9\u30a6\u30b6\u4e0a\u306e JavaScript \u3067\u6b63\u898f\u8868\u73fe\u3092\u6271\u3046\u3068\u304d\u306e\u6ce8\u610f\u70b9\u306b\u3064\u3044\u3066\u89e6\u308c\u3066\u307f\u307e\u3057\u305f\u3002\u3082\u3057\u30b3\u30e1\u30f3\u30c8\u3084\u3054\u610f\u898b\u7b49\u3042\u308a\u307e\u3057\u305f\u3089 <a href=\"https:\/\/twitter.com\/TaichiMasuyama\">\u5897\u5c71\u306e Twitter<\/a> \u306e DM \u306b\u3066\u6559\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>\u53c2\u8003\u6587\u732e<\/h1>\n<ul>\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/36911960\/javascript-regexp-constructor-vs-regex-literal\">https:\/\/stackoverflow.com\/questions\/36911960\/javascript-regexp-constructor-vs-regex-literal<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/RegExp\">https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/RegExp<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/standard\/base-types\/compilation-and-reuse-in-regular-expressions\">https:\/\/docs.microsoft.com\/en-us\/dotnet\/standard\/base-types\/compilation-and-reuse-in-regular-expressions<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u7686\u3055\u3093\u3053\u3093\u306b\u3061\u306f\uff01WESEEK \u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u30a8\u30f3\u30b8\u30cb\u30a2\u306e \u5897\u5c71 \u3067\u3059\u3002 \u4eca\u56de\u306f\u30d6\u30e9\u30a6\u30b6\u4e0a\u3067\u5b9f\u884c\u3055\u308c\u308b JavaScript \u306e\u6b63\u898f\u8868\u73fe\u304c\u30c6\u30fc\u30de\u3067\u3059\u3002\u6b63\u898f\u8868\u73fe\u30ea\u30c6\u30e9\u30eb\u3068 RegExp \u30af\u30e9\u30b9\u306f\u4f55\u304c\u9055\u3046\u306e\u304b\u3001\u3069\u3093\u306a\u30e1\u30ea\u30c3\u30c8\u30c7<\/p>\n","protected":false},"author":3,"featured_media":3185,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[31,52,166],"tags":[],"_links":{"self":[{"href":"https:\/\/weseek.co.jp\/tech\/wp-json\/wp\/v2\/posts\/3337"}],"collection":[{"href":"https:\/\/weseek.co.jp\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/weseek.co.jp\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/weseek.co.jp\/tech\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/weseek.co.jp\/tech\/wp-json\/wp\/v2\/comments?post=3337"}],"version-history":[{"count":6,"href":"https:\/\/weseek.co.jp\/tech\/wp-json\/wp\/v2\/posts\/3337\/revisions"}],"predecessor-version":[{"id":4235,"href":"https:\/\/weseek.co.jp\/tech\/wp-json\/wp\/v2\/posts\/3337\/revisions\/4235"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/weseek.co.jp\/tech\/wp-json\/wp\/v2\/media\/3185"}],"wp:attachment":[{"href":"https:\/\/weseek.co.jp\/tech\/wp-json\/wp\/v2\/media?parent=3337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/weseek.co.jp\/tech\/wp-json\/wp\/v2\/categories?post=3337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/weseek.co.jp\/tech\/wp-json\/wp\/v2\/tags?post=3337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}