Editing
Regular expression in Mandarin
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== 快速查表 == 說明: (1) sample 藍色網底處代表符合規則的文字、(2) 同一文字規則可以有多種表示法 <table border="1" style="width:100%" class="wikitable"> <tr > <th style="background-color: #E0E0E0;"> 文字規則 </th> <th style="background-color: #E0E0E0; width:260px;"> sample </th> <th style="background-color: #9c9ca3;"> 對立的文字規則 </th> <th style="background-color: #9c9ca3; width:260px;"> sample</th> </tr> <tr> <td> 任意一個文字(包含空白,但不包含換行符號) <br /> {{kbd | key = <nowiki>.</nowiki>}} </td> <td><span style="background:#C6E3FF">W</span>hat Does the Fox Say? 12 狐狸怎叫 34</td> <td></td> <td></td> </tr> <tr> <td> 任意文字(包含空白),出現1次或0次 <br /> {{kbd | key = <nowiki>.?</nowiki>}} = {{kbd | key = <nowiki>.{0,1}</nowiki>}}</td> <td><span style="background:#C6E3FF">W</span>hat Does the Fox Say? 12 狐狸怎叫 34</td> <td></td> <td></td> </tr> <tr> <td> 任意次的多個文字(包含空白) <br /> {{kbd | key = <nowiki>.*</nowiki>}} ={{kbd | key = <nowiki> .{0,}</nowiki>}}</td> <td><span style="background:#C6E3FF">What Does the Fox Say? 12 狐狸怎叫 34</span></td> <td></td> <td></td> </tr> <tr> <td> 任意次的文字(包含空白),至少出現1次 <br /> {{kbd | key = <nowiki>.+</nowiki>}} = {{kbd | key = <nowiki>.{1,}</nowiki>}}</td> <td><span style="background:#C6E3FF">What Does the Fox Say? 12 狐狸怎叫 34</span></td> <td></td> <td></td> </tr> <tr> <td> 任意次的空白或換行符號 (至少出現1次的空白或換行符號) <br /> {{kbd | key = <nowiki>\s+</nowiki>}} </td> <td>What<span style="background:#C6E3FF"> </span>Does the Fox Say? 12 狐狸怎叫 34</td> <td>任意多個文字(不包含空白或換行符號) <br /> {{kbd | key = <nowiki>[^\s]+</nowiki>}} ={{kbd | key = <nowiki> [^\s]{1,}</nowiki>}} = {{kbd | key = <nowiki> [\S]+</nowiki>}} = {{kbd | key = <nowiki>[^ ]+</nowiki>}}</td> <td><span style="background:#C6E3FF">What</span> Does the Fox Say? 12 狐狸怎叫 34</td> </tr> <tr> <td> 任意次的 ASCII character (包含英文、數字和空白) [http://regexr.com/3aom2 demo]<ref>[http://www.asciitable.com/ Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion]</ref> <br /> {{kbd | key = <nowiki>[\x00-\x80]+</nowiki>}} 或 {{kbd | key = <nowiki>[[:ascii:]]+</nowiki>}}<ref>[https://stackoverflow.com/questions/24903140/regex-for-any-english-ascii-character-including-special-characters php - Regex for Any English ASCII Character Including Special Characters - Stack Overflow]</ref></td> <td><span style="background:#C6E3FF">What Does the Fox Say? 12</span> 狐狸怎叫 34</td> <td>非 ASCII,即中文出現任意次<br /> {{kbd | key = <nowiki>[^\x00-\x80]+</nowiki>}}</td> <td>What Does the Fox Say? 12 <span style="background:#C6E3FF">狐狸怎叫</span> 34</td> </tr> <tr> <td> 任意次的大小寫英文、數字和底線符號( _ ) (不包含空白) ([https://regex101.com/r/gIKB6a/1 demo])<br /> {{kbd | key = <nowiki>[\w]+</nowiki>}} = {{kbd | key = <nowiki>[a-zA-Z0-9_]+</nowiki>}} <br /> PHP 加上 {{kbd | key =u}} 修飾語,則可支援中文字 </td> <td><span style="background:#C6E3FF">What</span> <span style="background:#C6E3FF">Does</span> <span style="background:#C6E3FF">the</span> <span style="background:#C6E3FF">Fox</span> <span style="background:#C6E3FF">Say</span>? <span style="background:#C6E3FF">12</span> 狐狸怎叫 <span style="background:#C6E3FF">_34</span></td> <td> 任意次的不是英文、數字和底線符號( _ )的文字 <br /> {{kbd | key = <nowiki>\W+</nowiki>}} = {{kbd | key = <nowiki>[^a-zA-Z0-9_]+</nowiki>}}</td> <td>[http://regexr.com/3bk4v demo]</td> </tr> <tr> <td> 任意次的數字(不包含空白) <br /> {{kbd | key = <nowiki>[\d]+</nowiki>}} = {{kbd | key = <nowiki>[0-9]+</nowiki>}}</td> <td>What Does the Fox Say? <span style="background:#C6E3FF">12</span> 狐狸怎叫 34</td> <td>不包含數字的任意次文字(包含空白 <br /> {{kbd | key = <nowiki>[^\d]+</nowiki>}} = {{kbd | key = <nowiki>[^0-9]+</nowiki>}} = {{kbd | key = <nowiki>\D+</nowiki>}} </td> <td><span style="background:#C6E3FF">What Does the Fox Say? </span>12 狐狸怎叫 34</td> </tr> <tr> <td> 任意次的中文字 <br /> {{kbd | key = <nowiki>[\p{Han}]+</nowiki>}} ([https://regex101.com/r/UYkdml/1 demo]、[[Regular expression#尋找中文、非英文的文字 | 詳細說明]])</td> <td>What Does the Fox Say? 12 <span style="background:#C6E3FF">狐狸怎叫</span> 34</td> <td>不包含中文字的任意次文字 <br /> {{kbd | key = <nowiki>[^\p{Han}]+</nowiki>}} ([https://regex101.com/r/Nk9GdA/1 demo])</td> <td></td> </tr> <tr> <td> 以「狐狸」開頭的行 <br /> {{kbd | key = <nowiki>^狐狸.*$</nowiki>}}<ref>[http://www.regular-expressions.info/completelines.html Regex Examples: Matching Whole Lines of Text That Satisfy Certain Requirements]</ref></td> <td> <span style="background:#C6E3FF">狐狸怎叫 34 What Does the Fox Say?</span><br /> 柴犬怎叫 What Does the shiba inu say? </td> <td>不以「狐狸」開頭的行 <br /> {{kbd | key = <nowiki>^(?!狐狸).*$</nowiki>}}<ref>[http://stackoverflow.com/questions/406230/regular-expression-to-match-text-that-doesnt-contain-a-word regex - Regular expression to match text that *doesn't* contain a word? - Stack Overflow]</ref> </td> <td> 狐狸怎叫 34 What Does the Fox Say?<br /> <span style="background:#C6E3FF">柴犬怎叫 What Does the shiba inu say?</span> </td> </tr> <tr> <td> 以「怎叫」結尾的行 <br /> {{kbd | key = <nowiki>^.*怎叫$</nowiki>}} <td> What Does the Fox Say? 12 狐狸怎叫 34<br /> <span style="background:#C6E3FF">What Does the shiba inu say? 柴犬怎叫</span> </td> <td>不以「怎叫」結尾的行 <br /> {{kbd | key = <nowiki>.*(?<!怎叫)$</nowiki>}}<ref>[http://stackoverflow.com/questions/16398471/regex-not-ending-with Regex not ending with - Stack Overflow]</ref></td> <td> <span style="background:#C6E3FF">What Does the Fox Say? 12 狐狸怎叫 34</span><br /> What Does the shiba inu say? 柴犬怎叫 </td> </tr> <tr> <td> 包含「狐狸」的行 <br /> {{kbd | key = <nowiki>^.*狐狸.*$</nowiki>}} 或 {{kbd | key = <nowiki>(狐狸)</nowiki>}} ([https://regex101.com/r/UEtYst/1 demo])</td> <td> <span style="background:#C6E3FF">What Does the Fox Say? 12 狐狸怎叫 34</span><br /> What Does the shiba inu say? 柴犬怎叫 </td> <td>不包含「狐狸」的行 ([https://regex101.com/r/rvncjU/1 demo]) <br /> {{kbd | key = <nowiki>^((?!狐狸).)*$</nowiki>}} </td> <td> What Does the Fox Say? 12 狐狸怎叫 34<br /> <span style="background:#C6E3FF">What Does the shiba inu say? 柴犬怎叫 </span> </td> </tr> <tr> <td> 布林邏輯 AND: 包含「狐狸」和「叫」的行 ([http://regexr.com/3aokl demo])<ref>[http://stackoverflow.com/questions/469913/regular-expressions-is-there-an-and-operator regex - Regular Expressions: Is there an AND operator? - Stack Overflow]</ref><br /> {{kbd | key = <nowiki>(?=.*狐狸)(?=.*叫).*</nowiki>}} 或 {{kbd | key = <nowiki>狐狸.*叫|叫.*狐狸</nowiki>}}</td> <td> <span style="background:#C6E3FF">What Does the Fox Say? 12 狐狸怎叫 34</span><br /> <span style="background:#C6E3FF">What Does the Fox Say? 12 不叫狐狸 34</span><br /> What Does the shiba inu say? 柴犬怎叫 </td> <td></td> <td></td> </tr> <tr> <td> 布林邏輯 OR: 包含「狐狸」或「叫」的行 ([https://regexr.com/6cu06 demo])<br /> {{kbd | key = <nowiki>.*(狐狸|叫).*</nowiki>}}</td> <td> <span style="background:#C6E3FF">What Does the Fox Say? 12 狐狸怎叫 34<br /> What Does the shiba inu say? 柴犬怎叫</span><br /> What Does the shiba inu say? 柴犬怎了 </td> <td>布林邏輯: 不包含「狐狸」也不包含「柴犬」的行<br /> {{kbd | key = <nowiki>^((?!狐狸|柴犬).)*$</nowiki>}}</td> <td>What Does the Fox Say? 12 狐狸怎叫 34<br /> What Does the shiba inu say? 柴犬怎叫<br /> <span style="background:#C6E3FF">What Does the Husky say? 哈士奇怎叫 </span></td> </tr> <tr> <td> 布林邏輯 NOT: 不包含「狐狸」,但包含「柴犬」的行 ([http://regexr.com/3aokr demo])<ref>[http://stackoverflow.com/questions/2953039/regular-expression-for-a-string-containing-one-word-but-not-another regex - Regular expression for a string containing one word but not another - Stack Overflow]</ref><br /> {{kbd | key = <nowiki>^((?!狐狸).)*(柴犬).*$</nowiki>}} = {{kbd | key = <nowiki>^(柴犬).*((?!狐狸).)*$</nowiki>}} = {{kbd | key = <nowiki>(柴犬).*((?!狐狸).)*</nowiki>}} (如果句子同時存在狐狸和柴犬會出錯) </td> <td> What Does the Fox Say? 12 狐狸怎叫 34<br /> <span style="background:#C6E3FF">What Does the shiba inu say? 柴犬怎叫</span> </td> <td></td> <td></td> </tr> </table>
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information