2017-10-04 2 views
0

éditeur de texte: Comment puis-je dupliquer deuxième ligne à tout autre 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">

J'ai besoin de dupliquer les lignes et changer le img src à un target="_blank" href pour les autres lignes et conserver la valeur img src la même.

Existe-t-il un moyen de le faire?

+1

Quel langage de programmation utilisez-vous pour générer le code? Ou voulez-vous utiliser Javascript? –

+0

j'utilise notepad ++ –

+0

remplacer '

Répondre

2
  • Ctrl + H
  • Trouvez ce que: ^\h*<img src=("[^"]+")>
  • Remplacer par: <a target="_blank" href="$1">\n$0
  • check Enrouler
  • check Expression régulière NE PAS VOIR . matches newline
  • Remplacer tous

Explication:

^   : 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 > 

remplacement:

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

Résultat par exemple donné:

<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"> 
0

Essayez d'utiliser & trouver par Regex remplacer:

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

espérons qu'il vous aidera.