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!
=== 將每項元素,加上引號框起來 === ==== 將陣列的每項元素,都加上引號框起來 ==== <pre> Elmo, Emie, Granny Bird, Herry Monster, 喀喀獸 修改成 'Elmo', 'Emie', 'Granny Bird', 'Herry Monster', '喀喀獸' </pre> 方法1: 使用 PHP {{exclaim}} 如果元素包含換行符號,不能用下面方法處理。 <pre> $users = array('Elmo', 'Emie', 'Granny Bird', 'Herry Monster', '喀喀獸'); //「單引號」相隔每個元素 $result = implode(",", preg_replace('/^(.*?)$/', "'$1'", $users)); //「雙引號」相隔每個元素 $result = implode(",", preg_replace('/^(.*?)$/', "\"$1\"", $users)); echo $result; </pre> Thanks, Joshua! More on [http://melikedev.com/2010/02/24/php-wrap-implode-array-elements-in-quotes/ PHP - Wrap Implode Array Elements in Quotes » Me Like Dev] 方法2: 使用 [http://www.sublimetext.com/ Sublime Text] 或 [https://zh-tw.emeditor.com/ EmEditor] * Find: {{kbd | key = <nowiki>([^\s|,]+)</nowiki>}} * 分隔符號 **「單引號」相隔每個元素 Replace with: {{kbd | key = <nowiki>'\1'</nowiki>}} **「雙引號」相隔每個元素 Replace with: {{kbd | key = <nowiki>"\1"</nowiki>}} 方法3: 使用 [https://notepad-plus-plus.org/ Notepad++]。啟用搜尋模式的「用類型表式」 * Find: {{kbd | key = <nowiki>([^\s|,]+)</nowiki>}} * 分隔符號 **「單引號」相隔每個元素 Replace with: {{kbd | key = <nowiki>'$1'</nowiki>}} **「雙引號」相隔每個元素 Replace with: {{kbd | key = <nowiki>"$1"</nowiki>}} <div style="float: left; width: 100%; position: relative; display: block; clear: left;"> <div style="width: 46%; float: left; margin:0 auto; position: relative; display: block; "> ==== 將每行的文字,都加上引號框起來,並且移除換行 ==== <pre> // before Elmo Emie Granny Bird // after 'Elmo', 'Emie', 'Granny Bird' </pre> 方法1: 使用 [http://www.sublimetext.com/ Sublime Text] 、[https://notepad-plus-plus.org/downloads/ Notepad++] 或 [https://zh-tw.emeditor.com/ EmEditor]。該方法有處理每行的前面或後面可能有一格或多格空白 如果使用 {{Mac}} 作業系統 * Find what: {{kbd | key = <nowiki>(\S+)(\s?)+$\n</nowiki>}} * Replace with: {{kbd | key = <nowiki>'\1', </nowiki>}} <br />(如果要使用雙引號框起來,則是 Replace with: {{kbd | key = <nowiki>"\1", </nowiki>}}) 如果使用 {{Win}} 作業系統,需要修改換行符號 {{kbd | key = <nowiki>\n</nowiki>}} 為 {{kbd | key = <nowiki>\r\n</nowiki>}} * Find what: {{kbd | key = <nowiki>(\S+)(\s?)+$\r\n</nowiki>}} on {{Mac}} * Replace with: {{kbd | key = <nowiki>'\1', </nowiki>}} <br />(如果要使用雙引號框起來,則是 Replace with: {{kbd | key = <nowiki>"\1", </nowiki>}}) 方法2: 使用 [http://www.sublimetext.com/ Sublime Text] 或 [https://zh-tw.emeditor.com/ EmEditor] {{exclaim}} 該方法沒有處理每行的後面可能有一格或多格空白 * Find what: {{kbd | key = <nowiki>(.*)$\n</nowiki>}} 或 {{kbd | key = <nowiki>(\S+)$\n</nowiki>}} 或 {{kbd | key = <nowiki>(\S+)\n</nowiki>}} * Replace with: {{kbd | key = <nowiki>'\1', </nowiki>}} More details on the page [[Add quotation at the start and end of each line | add quotation at the start and end of each line]]. </div> <div style="width: 46%; float: left; margin:0 auto; position: absolute; display: block; left: 54%; top: 0;"> ==== 將引號框起來的文字,還原成逐行顯示,並且移除分隔符號 (,) ==== <pre> // before 'Elmo', 'Emie', 'Granny Bird' // after Elmo Emie Granny Bird </pre> 方法: 使用 [http://www.sublimetext.com/ Sublime Text] 或 [https://zh-tw.emeditor.com/ EmEditor]。該方法有處理每行的前面或後面可能有一格或多格空白 * Find what: {{kbd | key = <nowiki>'(([^,|^'])+)',?\s?</nowiki>}} * Replace with: {{kbd | key = <nowiki>\1\n</nowiki>}} </div> </div> <div style="clear:both;"> </div>
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