SlideShare une entreprise Scribd logo
1  sur  15
Télécharger pour lire hors ligne
Unicodeを触る
2023-02-28
@takenspc
最終的に話す内容
• 正規表現のvフラグ
• ECMAScript proposal: RegExp `v` flag with set notation + properties of
strings
• Stage 3
• V8 11.0/Google Chrome 112で利用可能
https://github.com/tc39/proposal-regexp-v-flag
今日の内容
•発表者の背景
•正規表現のuフラグで出来ること
•正規表現のvフラグに期待すること
発表者の背景
•書籍ではないものの文字やテキストを扱うことが多い
• 文字が意図せず変わっていたり、意図しない文字がつかわれていたりする
ことをチェックする機会がある
•一次調査などで正規表現を使うことが多い
正規表現のuフラグで出来ること
•uフラグ
/…正規表現…/ // uフラグなし
/…正規表現…/u // uフラグあり
•uフラグでできること(の一部)
• Unicodeの情報を使ってマッチ対象を表現
例:「カタカナ」を探したい
• /p{sc=Katakana}/u
• UnicodeでScriptがKatakanaに分類される文字にマッチ
• 一般的なカタカナの概念とは少し異なる
• 半角カタカナ(アイウ)や組文字(㌱㌀㍇)、丸付き文字(㋐㋑㋒)などにも
マッチする
• 長音記号(ー)にはマッチしない
• NFDや半角カタカナの濁点や半濁点にはマッチしない
マッチ対象を増やすことはできる
• /[p{sc=Katakana}u3099-u309Du30FCuFF9EuFF9FuFF70]/u
• UnicodeでScriptがKatakanaに分類される文字と次のものにマッチ
• u3099-u309D: NFDなどの濁点・半濁点
• u30FC:長音記号
• uFF9EuFF9F:半角カタカナの濁点・半濁点
• uFF70:半角カタカナの長音記号
マッチ対象を減らすには?
•vフラグを使うと簡単に書ける
正規表現のvフラグに期待すること
• vフラグ
/…正規表現…/ // uフラグなし
/…正規表現…/u // uフラグあり
/…正規表現…/v // vフラグあり
• vフラグでできること(の一部)
• マッチ対象を減らせる
例:原稿から意図せずコピーされる文字
• PowerPointなどで強制改行しているテキストをコピーすると改行が垂直タブ
(U+000B)としてコピーされる
• 某Webサービスのリッチテキストをコピーするとゼロ幅空白(U+200B)が入る
……
個別に対応していくと終わらないため、まとめて検索したい
制御文字などを探したい
•/p{gc=Other}/u
• UnicodeでGeneral CategoryがOtherに分類される文字にマッチ
• この正規表現は実用しにくい
• 空白やタブ、改行などにもマッチ
• 絵文字で使われる制御用の文字(U+200D Zero Width Joiner)もマッチ
マッチ対象を減らす
• /[p{gc=Other}--[ trnu200D]]/v
• vフラグを使うとUnicodeでGeneral CategoryがOtherに分類される文字か
ら--以降を除いてマッチ
• 空白やタブ、改行などにはマッチしない
• 絵文字で使われる制御用の文字(U+200D Zero Width Joiner)には
マッチしない
まとめ
• 正規表現のuフラグ:Unicodeのプロパティを使ってマッチ対象を表現
• Unicodeのプロパティは要件と合わないこともあり、マッチ対象の調整が発生す
ることも
• 既存の正規表現でもマッチ対象を増やすことは可能
• vフラグを使うとマッチ対象を減らすことが可能
• 正規表現やUnicodeを上手く使ってテキストと付き合いたい
参考
•ECMAScript proposal: RegExp v flag with set notation +
properties of strings
•RegExp v flag with set notation and properties of strings · V8
•Unicode Utilities: Description and Index

Contenu connexe

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)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 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd 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 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 IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...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
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 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 ChatGPTEverything 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 EngineeringsProduct 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 HealthHow 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.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO 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)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 2024How 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 InsightsSocial 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 2024Trends 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 summary5 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 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 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 IntentGoogle'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 How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe 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...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Unicodeを触る