Submit Search
Upload
ECMAScriptを正規表現で解く
•
Download as PPTX, PDF
•
1 like
•
964 views
P
polygonplanet
Follow
ECMAScriptを正規表現で字句解析します
Read less
Read more
Technology
Report
Share
Report
Share
1 of 26
Download now
Recommended
Nielsen chuang-4 3-2
Nielsen chuang-4 3-2
GM3D
Ilerpg Study 005
Ilerpg Study 005
Yoshiki Ushida
DMM.comにおけるビッグデータ処理のためのSQL活用術
DMM.comにおけるビッグデータ処理のためのSQL活用術
DMM.com
ILE-RPG Study 001
ILE-RPG Study 001
Yoshiki Ushida
黄金比.再帰
黄金比.再帰
Yoshiteru Kamiyama
積分要素の過渡応答性(MATLAB)
積分要素の過渡応答性(MATLAB)
Tsuyoshi Horigome
2次遅れの積分要素の過渡応答性(MATLAB)
2次遅れの積分要素の過渡応答性(MATLAB)
Tsuyoshi Horigome
1次遅れの積分要素の過渡応答性2(MATLAB)
1次遅れの積分要素の過渡応答性2(MATLAB)
Tsuyoshi Horigome
Recommended
Nielsen chuang-4 3-2
Nielsen chuang-4 3-2
GM3D
Ilerpg Study 005
Ilerpg Study 005
Yoshiki Ushida
DMM.comにおけるビッグデータ処理のためのSQL活用術
DMM.comにおけるビッグデータ処理のためのSQL活用術
DMM.com
ILE-RPG Study 001
ILE-RPG Study 001
Yoshiki Ushida
黄金比.再帰
黄金比.再帰
Yoshiteru Kamiyama
積分要素の過渡応答性(MATLAB)
積分要素の過渡応答性(MATLAB)
Tsuyoshi Horigome
2次遅れの積分要素の過渡応答性(MATLAB)
2次遅れの積分要素の過渡応答性(MATLAB)
Tsuyoshi Horigome
1次遅れの積分要素の過渡応答性2(MATLAB)
1次遅れの積分要素の過渡応答性2(MATLAB)
Tsuyoshi Horigome
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
WSO2
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
Toru Tamaki
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
sn679259
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
iPride Co., Ltd.
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
Toru Tamaki
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Hiroshi Tomioka
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
CRI Japan, Inc.
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
atsushi061452
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
iPride Co., Ltd.
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
iPride Co., Ltd.
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
CRI Japan, Inc.
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
More Related Content
Recently uploaded
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
WSO2
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
Toru Tamaki
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
sn679259
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
iPride Co., Ltd.
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
Toru Tamaki
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Hiroshi Tomioka
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
CRI Japan, Inc.
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
atsushi061452
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
iPride Co., Ltd.
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
iPride Co., Ltd.
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
CRI Japan, Inc.
Recently uploaded
(11)
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
Featured
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Featured
(20)
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
Skeleton Culture Code
Skeleton Culture Code
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
How to have difficult conversations
How to have difficult conversations
Introduction to Data Science
Introduction to Data Science
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
The six step guide to practical project management
The six step guide to practical project management
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
ECMAScriptを正規表現で解く
1.
ECMAScriptを正規表現で解く @polygon_planet
2.
正規表現で字句解析してみる var a =
100; var a = 100 ;
3.
仕様 ECMA-262 7ᵗʰ Edition /
June 2016 ECMAScript® 2016 Language Specification http://www.ecma-international.org/ecma-262/7.0/index.html https://github.com/tc39/ecma262
4.
わりと大雑把だけど仕様に 沿った感じで
5.
改行コード (LineTerminator) /[nru2028u2029]/ <LF> n
0x000A LINE FEED <CR> r 0x000D CARRIAGE RETURN <LS> U+2028 LINE SEPARATOR <PS> U+2029 PARAGRAPH SEPARATOR
6.
改行 (LineTerminatorSequence) /rn|[nru2028u2029]/
7.
空白 (WhiteSpace) /(?:(?![nru2028u2029])s)+/ <TAB> <VT> <FF> <SP> <NBSP> <ZWNBSP> <USP>
8.
コメント (Comments) //*[sS]*?*/ |//[^nru2028u2029]*/ <!-- コメント -->
コメント ※ HTML-like Commentsは省略
9.
文字列リテラル (StringLiteral) /'(?:.|[^'])*'/ 'abc' 'ab'c' 'ab c' 改行にマッチしてしまう
10.
/'(?:[sS]|[^'rn])*'/ 'abc' 'ab'c' 'ab c' マッチしない 'ab c' マッチする
11.
/'(?:[sS]|[^'rn])*'/ マッチしない 'aaa<CR><LF> bbb<CR><LF> ccc'
12.
/'(?:rn|[sS]|[^'rn])*'/ マッチする 'aaa<CR><LF> bbb<CR><LF> ccc'
13.
文字列リテラル (StringLiteral) /'(?:rn|[sS]|[^'nru2028u20 29])*'|"(?:rn|[sS]|[^"nru 2028u2029])*"/
14.
数値リテラル (NumericLiteral) / 0(?:[xX][0-9a-fA-F]+ |[oO][0-7]+ |[bB][01]+ ) |
(?:d+(?:.d*)?|.d+)(?:[eE][+-]?d+)? | [1-9]d* | 0[0-7]+ /
15.
テンプレートリテラル (TemplateLiteral) /`(?:[sS]|[^`])*`/ `abc` `ab`c`
16.
`abc${` `}ghi`def Expressionに対応できてない 正規表現で無限の再帰が必要 /`(?:[sS]|[^`])*`/
17.
/`(?:[sS]|${(?:[sS]|[^{}]| {(?:[^{}]*(?:{[^{}]*})?)*})*}|[^` ])*`/ ` ${ `${ `${ 1 +
1 }` }` } ` ある程度のネストまでマッチ
18.
正規表現リテラル (RegularExpressionLiteral) //(?![*/])(?:[sS]|[^/rn])+ /(?:[gimuy]+b|)/ /a/ /abc/i // /**/ /ab/c/ マッチしない マッチしない
19.
//(?![*/])(?:[sS]|[^/rn])+ /(?:[gimuy]+b|)/ /[/]/ 正しくマッチしない
20.
正規表現リテラル (RegularExpressionLiteral) //(?![*/])(?:[sS]|[(?:[sS] |[^]nru2028u2029])*]|[^/nr u2028u2029])+/(?:[gimuy]+b|)/ /[/]/ マッチする
21.
区切り子と演算子 (Punctuators) />>>=?|.{3}|<<=|===|!==|>>=|**=|+ +(?=+)|--(?=-)|[=!<>*%+/&|^- ]=|&&||||++|--|<<|>>|=>|**|[- +*/%<>=&|^~!?:;,.()[]{}]/
22.
識別子 (Identifier) /(?:u(?:[0-9a-fA-F]{4}|{[0-9a-fA- F]+})|[^s+/%*=&|^~<>!?:;,.()[]{ }'"`-])+/
23.
できたパターン /(/*[sS]*?*/|//[^nru2028u2029]*|<!--[^rnu2028u2029]*|(?: ^|(?:rn|[nru2028u2029]))(?:(?:(?![nru2028u2029])s)+)?-->[^n ru2028u2029]*|`(?:[sS]|${(?:[sS]|[^{}]|{(?:[^{}]*(?:{[^{ }]*})?)*})*}|[^`])*`(?=s*(?:(?!s*[/<>*%`^"'w$-])[^/<>*%`^' "({[w$-]|[!=]==?||||&&|/[*/]|[,.;:!?)}]nru2028u2029]|$))|"(?: rn|[sS]|[^"nru2028u2029])*"|'(?:rn|[sS]|[^'nru20 28u2029])*'|(?:/(?![*/])(?:[sS]|[(?:[sS]|[^]nru2028u2 029])*]|[^/nru2028u2029])+/(?:[gimuy]+b|))(?=s*(?:(?!s*[/ <>*%`^"'w$-])[^/<>*%`^'"({[w$-]|[!=]==?||||&&|/[*/]|[,.;:!?)} ]nru2028u2029]|$))|0(?:[xX][0-9a-fA-F]+|[oO][0-7]+|[bB][01]+)|(?:d +(?:.d*)?|.d+)(?:[eE][+-]?d+)?|[1-9]d*|0[0-7]+|(?:>>>=?|.{3}|<<=| ===|!==|>>=|**=|++(?=+)|--(?=-)|[=!<>*%+/&|^-]=|&&||||++|--|<< |>>|=>|**|[-+*/%<>=&|^~!?:;,.()[]{}])|(?:(?![nru2028u2029])s)+| (?:rn|[nru2028u2029])|(?:u(?:[0-9a-fA-F]{4}|{[0-9a-fA-F]+})|[^ s+/%*=&|^~<>!?:;,.()[]{}'"`-])+)/g
24.
使い方 var pattern =
/.../g; var code = 'var a = 100'; var tokens = code.match(pattern); console.log(tokens); //['var', ' ', 'a', ' ', '=', ' ', '100']
25.
RegExp Lookbehind Assertions 肯定的後読み
(?<=pattern) 否定的後読み (?<!pattern) https://github.com/tc39/proposal-regexp-lookbehind が使えるようになったらもう少し厳密にできそう。 ※ Chromeでは実装されている ※ 現在 Stage 2
26.
デモ http://jsfiddle.net/polygonplanet/mu56y85b/
Download now