<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Regex on Ricky</title><link>https://linzeyan.github.io/zh-tw/categories/regex/</link><description>Recent content in Regex on Ricky</description><generator>Hugo -- gohugo.io</generator><language>zh-tw</language><lastBuildDate>Sun, 19 May 2024 14:37:00 +0800</lastBuildDate><atom:link href="https://linzeyan.github.io/zh-tw/categories/regex/index.xml" rel="self" type="application/rss+xml"/><item><title>Emoji 正则匹配</title><link>https://linzeyan.github.io/zh-tw/posts/2024/20240519-emoji-regexp/</link><pubDate>Sun, 19 May 2024 14:37:00 +0800</pubDate><guid>https://linzeyan.github.io/zh-tw/posts/2024/20240519-emoji-regexp/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://taxodium.ink/post/emoji-regexp/" target="_blank" rel="noopener">Emoji 正则匹配&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>&lt;code>/\p{Emoji}/u&lt;/code>&lt;/p>
&lt;p>既然是匹配 Emoji，那么 loneProperty (\p{loneProperty}) 就应该是 Emoji ? 实际测试并不符合需求，因为在 Emoji 官方文档中， 123456789*# 也是被看作是 Emoji， 如果用这个正则的话，就会把数字也认为是 Emoji，不符合只排除特殊表情的要求。&lt;/p>
&lt;p>&lt;code>/\p{Extended_Pictographic}/u&lt;/code>&lt;/p>
&lt;p>而 Extended_Pictographic 表示的 Emoji 才是我们认为的那些表情符号。&lt;/p></description></item><item><title>Markdown 語法的正則表達式</title><link>https://linzeyan.github.io/zh-tw/posts/2021/20211029-regex-for-md/</link><pubDate>Fri, 29 Oct 2021 10:19:41 +0800</pubDate><guid>https://linzeyan.github.io/zh-tw/posts/2021/20211029-regex-for-md/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://chubakbidpaa.com/interesting/2021/09/28/regex-for-md.html" target="_blank" rel="noopener">Markdown 語法的正則表達式&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.markdownguide.org/basic-syntax/" target="_blank" rel="noopener">基本語法&lt;/a>&lt;/li>
&lt;/ul>
&lt;pre tabindex="0">&lt;code># Headings
headerOne = `(#{1}\s)(.*)`
headeTwo = `(#{2}\s)(.*)`
headerThree = `(#{3}\s)(.*)`
headerFour = `(#{4}\s)(.*)`
headerFive = `(#{5}\s)(.*)`
headerSix = `(#{6}\s)(.*)`
# Bold and Italic Text
boldItalicText = `(\*|\_)+(\S+)(\*|\_)+`
# Links
linkText = `(\[.*\])(\((http)(?:s)?(\:\/\/).*\))`
# Images
imageFile = `(\!)(\[(?:.*)?\])(\(.*(\.(jpg|png|gif|tiff|bmp))(?:(\s\&amp;#34;|\&amp;#39;)(\w|\W|\d)+(\&amp;#34;|\&amp;#39;))?\)`
# Unordered List
listText = `(^(\W{1})(\s)(.*)(?:$)?)+`
# Numbered Text
numberedListText = `(^(\d+\.)(\s)(.*)(?:$)?)+`
# Block Quotes
blockQuote = `((^(\&amp;gt;{1})(\s)(.*)(?:$)?)+`
# Inline Code
inlineCode = &amp;#34;(\\`{1})(.*)(\\`{1})&amp;#34;
# Code Block
codeBlock = &amp;#34;(\\`{3}\\n+)(.*)(\\n+\\`{3})&amp;#34;
# Horizontal Line
horizontalLine = `(\=|\-|\*){3}`
# Email Text
emailText = `(\&amp;lt;{1})(\S+@\S+)(\&amp;gt;{1})`
# TABLES
tableText = `(((\|)([a-zA-Z\d+\s#!@&amp;#39;&amp;#34;():;\\\/.\[\]\^&amp;lt;={$}&amp;gt;?(?!-))]+))+(\|))(?:\n)?((\|)(-+))+(\|)(\n)((\|)(\W+|\w+|\S+))+(\|$)`
&lt;/code>&lt;/pre></description></item><item><title>是否有正規表示式可以檢測有效的正規表示式？</title><link>https://linzeyan.github.io/zh-tw/posts/2019/20191004-is-there-a-regular-expression-to-detect-a-valid-regular-expression/</link><pubDate>Fri, 04 Oct 2019 14:44:38 +0800</pubDate><guid>https://linzeyan.github.io/zh-tw/posts/2019/20191004-is-there-a-regular-expression-to-detect-a-valid-regular-expression/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://stackoverflow.com/questions/172303/is-there-a-regular-expression-to-detect-a-valid-regular-expression" target="_blank" rel="noopener">是否有正規表示式可以檢測有效的正規表示式？&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>這是一個遞迴正則，許多正則引擎不支援。基於 PCRE 的引擎應該支援。&lt;/p>
&lt;pre tabindex="0">&lt;code>/
^ # start of string
( # first group start
(?:
(?:[^?+*{}()[\]\\|]+ # literals and ^, $
| \\. # escaped characters
| \[ (?: \^?\\. | \^[^\\] | [^\\^] ) # character classes
(?: [^\]\\]+ | \\. )* \]
| \( (?:\?[:=!]|\?&amp;lt;[=!]|\?&amp;gt;)? (?1)?? \) # parenthesis, with recursive content
| \(\? (?:R|[+-]?\d+) \) # recursive matching
)
(?: (?:[?+*]|\{\d+(?:,\d*)?\}) [?+]? )? # quantifiers
| \| # alternative
)* # repeat content
) # end first group
$ # end of string
/
&lt;/code>&lt;/pre>&lt;p>移除空白與註解後&lt;/p></description></item></channel></rss>