Regular expression: Difference between revisions

Jump to navigation Jump to search
Line 160: Line 160:
## Replace with: {{kbd | key = <nowiki>, </nowiki>}}
## Replace with: {{kbd | key = <nowiki>, </nowiki>}}
# click "Replace all"
# click "Replace all"
==== 方案2: Notepad++ ====
使用[http://notepad-plus-plus.org/ Notepad++]軟體
# 選單: 尋找 -> 取代
# 搜尋模式: 勾選「增強模式」 (不是勾選「用類型表式」)
## 尋找目標: {{kbd | key = <nowiki>\n</nowiki>}} (換行符號)
## 取代成: {{kbd | key = <nowiki>, </nowiki>}}
# 勾選全部取代
相關資料: [http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Replacing_Newlines How To Replace Line Ends, thus changing the line layout] last visited: 2010-01-27
==== 方案3: Microsoft Word ====
使用Microsoft Word 2002軟體
# 選單: 編輯 -> 取代
# 勾選增強模式
## 尋找目標: {{kbd | key = <nowiki>^p</nowiki>}} (段落標記)
## 取代為: {{kbd | key = <nowiki>, </nowiki>}}
# 勾選全部取代
==== 方案4: Sed command for linux ====
{{kbd | key=<nowiki>sed 's/要被取代的字串/新的字串/g' old.filename > new.filename</nowiki>}}<ref>[http://linux.vbird.org/linux_basic/0330regularex.php#sed_replace 鳥哥的 Linux 私房菜 -- 正規表示法 (regular expression, RE) 與文件格式化處理]</ref>
(1)要被取代的字串: :a;N;$!ba;s/\n
(2)新的字串: ;
{{kbd | key=<nowiki>sed ':a;N;$!ba;s/\n/; /g' old.filename > new.filename</nowiki>}} <ref>參考 [http://stackoverflow.com/questions/1251999/sed-how-can-i-replace-a-newline-n unix - sed: How can I replace a newline? ]</ref>




<div style="float: left; width: 100%; position: relative; display: block; clear: left;">
<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; ">
<div style="width: 46%;  float: left; margin:0 auto; position: relative; display: block; ">
==== 將每行的文字,移除換行,並且都加上逗號分隔 ====
===== 將每行的文字,移除換行,並且都加上逗號分隔 =====
<pre>
<pre>
// before
// before
Line 211: Line 183:
<div style="width: 46%; float: left; margin:0 auto; position: absolute; display: block; left: 54%; top: 0;">
<div style="width: 46%; float: left; margin:0 auto; position: absolute; display: block; left: 54%; top: 0;">


==== 將逗號分隔的文字,還原成逐行顯示,並且移除分隔符號 (,) ====
===== 將逗號分隔的文字,還原成逐行顯示,並且移除分隔符號 (,) =====
<pre>
<pre>
// before
// before
Line 227: Line 199:
</div>
</div>
</div>
</div>
<div style="clear:both;">&nbsp;</div>
==== 方案2: Notepad++ ====
使用[http://notepad-plus-plus.org/ Notepad++]軟體
# 選單: 尋找 -> 取代
# 搜尋模式: 勾選「增強模式」 (不是勾選「用類型表式」)
## 尋找目標: {{kbd | key = <nowiki>\n</nowiki>}} (換行符號)
## 取代成: {{kbd | key = <nowiki>, </nowiki>}}
# 勾選全部取代


<div style="clear:both;">&nbsp;</div>
相關資料: [http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Replacing_Newlines How To Replace Line Ends, thus changing the line layout] last visited: 2010-01-27
 
==== 方案3: Microsoft Word ====
使用Microsoft Word 2002軟體
# 選單: 編輯 -> 取代
# 勾選增強模式
## 尋找目標: {{kbd | key = <nowiki>^p</nowiki>}} (段落標記)
## 取代為: {{kbd | key = <nowiki>, </nowiki>}}
# 勾選全部取代
 
==== 方案4: Sed command for linux ====
 
{{kbd | key=<nowiki>sed 's/要被取代的字串/新的字串/g' old.filename > new.filename</nowiki>}}<ref>[http://linux.vbird.org/linux_basic/0330regularex.php#sed_replace 鳥哥的 Linux 私房菜 -- 正規表示法 (regular expression, RE) 與文件格式化處理]</ref>
 
(1)要被取代的字串: :a;N;$!ba;s/\n
(2)新的字串: ;  
 
{{kbd | key=<nowiki>sed ':a;N;$!ba;s/\n/; /g' old.filename > new.filename</nowiki>}} <ref>參考 [http://stackoverflow.com/questions/1251999/sed-how-can-i-replace-a-newline-n unix - sed: How can I replace a newline? ]</ref>
 
==== 方案5: 使用支援十六進位編輯 (HEX) 的編輯軟體 ====
 
使用支援十六進位編輯 (HEX) 的編輯軟體,例如: [https://itunes.apple.com/tw/app/ihex-hex-editor/id909566003?mt=12 ‎iHex - Hex Editor] for {{Mac}}
# 選單 Edit -> Find
# Find: {{kbd | key=<nowiki>0A</nowiki>}} 換行符號
# Replace: {{kbd | key=<nowiki>2c 20</nowiki>}} 其中 2c 是逗號, 20 是空白
# 儲存檔案


=== Find IP address ===
=== Find IP address ===

Navigation menu