簡體   English   中英

使用Perl用特殊字符替換字符串

[英]Replace string with special characters using perl

我正在嘗試替換一個字符串

</string§>

new string line 1
new string line 2

在Linux上使用perl。

問題是,它將不接受<和>以及/。

這就是我得到的:

perl -i -pe 's/\<\/string§\>/new string line 1 \n new string line 2/se' file.xml

有人可以幫忙嗎?

謝謝!

您不需要se修飾符,還可以使用其他正則表達式除法器( /除外)來避免轉義:

perl -pe 's~</string§>~new string line 1 \nnew string line 2~' file.xml
new string line 1
new string line 2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM