文本编辑器:如何将第二行复制到其他代码

Text editor: How can I duplicate second line to other code

<a target="_blank" href="img_forest.jpg">
  <img src="img_forest.jpg">

  <img src="img_forest110.jpg">

  <img src="img_forest228.jpg">

  <img src="img_forest334.jpg">

我需要复制行并更改 img src 到其他行的 target="_blank" href 并保持 img src 值相同。

有办法吗?

尝试使用正则表达式查找和替换:

Find: <img src=\"(.*)\"> (you may add / at beginning and ending position if needed)
Replace: <a target="_blank" href=""> (add / at beginning or ending if needed)

希望对你有帮助。

  • Ctrl+H
  • 查找内容:^\h*<img src=("[^"]+")>
  • 替换为:<a target="_blank" href="">\n[=14=]
  • 选中环绕
  • 检查正则表达式 不勾选. matches newline
  • 全部替换

解释:

^           : begining of line
\h*         : 0 or more horizontal spaces (space or tabulation)
<img src=   : literally <img src=
(           : start group 1
  "[^"]+"   : 1 or more non quote character between quotes
)           : end group 1
>           : literally >

替换:

<a target="_blank" href="">   : <a...> tag, with value in group 1 (ie. image filename)
\n                              : linebreak (you could use "\r\n")
[=11=]                              : content of group 0 (ie. the whole match: <img ...>)

给定示例的结果:

<a target="_blank" href="img_forest.jpg"">
  <img src="img_forest.jpg">

<a target="_blank" href="img_forest110.jpg"">
  <img src="img_forest110.jpg">

<a target="_blank" href="img_forest228.jpg"">
  <img src="img_forest228.jpg">

<a target="_blank" href="img_forest334.jpg"">
  <img src="img_forest334.jpg">