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
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
FumieNakayama
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
Yuki Kikuchi
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
FumieNakayama
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
sugiuralab
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
博三 太田
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
akihisamiyanaga1
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
UEHARA, Tetsutaro
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版) 2024年4月作成
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版) 2024年4月作成
Hiroshi Tomioka
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
Hiroki Ichikura
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
More Related Content
Recently uploaded
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
FumieNakayama
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
Yuki Kikuchi
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
FumieNakayama
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
sugiuralab
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
博三 太田
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
akihisamiyanaga1
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
UEHARA, Tetsutaro
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版) 2024年4月作成
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版) 2024年4月作成
Hiroshi Tomioka
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
Hiroki Ichikura
Recently uploaded
(9)
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版) 2024年4月作成
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版) 2024年4月作成
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
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