Remplacer une sous chaîne par une autre
Bonjour à tous.
Actuellement j'ai une chaine (provenant d'un fichier DOS) qui ressemble à cela :
Code:
1 2 3 4 5 6 7 8 9
|
Compressing MySQL Datafiles\totalsens\customerssitesacquisitors.frm
Compressing MySQL Datafiles\totalsens\customerssitesacquisitors.ibd
WARNINGS: The process cannot access the file because it is being used by another process.
WARNINGSS for files:
d:\CopyLocalLog.txt : The process cannot access the file because it is being used by another process.
!This is a Warning! |
J'aimerais changer toutes les lignes où on retrouve le mot WARNING par :
Code:
1 2
|
<span style=\"background-color :red;\">...</span> |
Donc mon fichier actuel devrait avoir l'air de ceci à la fin :
Code:
1 2 3 4 5 6 7 8 9
|
Compressing MySQL Datafiles\totalsens\customerssitesacquisitors.frm
Compressing MySQL Datafiles\totalsens\customerssitesacquisitors.ibd
<span style=\"background-color :red;\">WARNINGS: The process cannot access the file because it is being used by another process.</span>
<span style=\"background-color :red;\">WARNINGSS for files:</span>
d:\CopyLocalLog.txt : The process cannot access the file because it is being used by another process.
<span style=\"background-color :red;\">!This is a Warning!</span> |
Je ne suis pas très habitué avec les RegEx mais j'ai toutefois commencé avec :
Code:
1 2 3
|
var text = ReadFile( "TestReplace.txt" );
text = text.replace( /.*WARNINGS.*\r\n/g, "<span style=\"background-color :red; color :white; font-weight :bold;\">???</span>" ); |
Merci pour votre aide :)