简体   繁体   中英

Perl Regex match and replace

I try insert new line after < /a>

I tried this 
perl -pe '/<\/a> $&\n /g' teste.txt

Example

Source code
<a href="/link/">link</a><a href="/link2/">link2</a>

Output

<a href="/link/">link</a>
<a href="/link2/">link2</a>

您缺少执行正则表达式替换的s命令。

perl -pe 's/<\/a>/$&\n /g' teste.txt

A plain /xxx/ will just perform a match, you need s/xxx/yyy/ to perform a single replacement, and a s/xxx/yyy/g to perform multiple replacements. You may also replace the / with another character such as | so you do not need to escape any characters, which makes it more readable.

perl -pe 's|</a>|$&\n|g;' teste.txt

Have a look at perldoc perlretut for a gentle introduction to perl regular expressions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM