Question Remplacer nom variable: Regex exemple

Plus d'informations
il y a 8 ans 8 mois #20617 par Christer Lofving
Exemple de base pour utiliser une Regex in PowerShell , peut changer plusieurs noms de variables ...

[code:1]'if $myvar = $nextvar -eq $null $myvar -neq $remainvar' >> logiciel.ps1
$subject = Get-Content logiciel.ps1

$regex = [regex] '\$[a-zA-Z0-9]{1,32}'
$matchdetails = $regex.Match($subject)

while ($matchdetails.Success) {
for ($i = 0; $i -lt $matchdetails.Groups.Count; $i++) {
$groupdetails = $matchdetails.Groups[$i]
if ($groupdetails.Success) {
if ($groupdetails.Value -eq '$myvar')
{
$subject = $subject.Replace($groupdetails.Value, '$my_new_var')
}
if ($groupdetails.Value -eq '$nextvar')
{
$subject = $subject.Replace($groupdetails.Value, '$changedvar')
}
}
}
$matchdetails = $matchdetails.NextMatch()
}

$subject > logiciel.ps1
[/code:1]

Message édité par: Sogeti, à: 11/08/15 15:54

Message édité par: Sogeti, à: 11/08/15 16:00<br><br>Message édité par: Sogeti, à: 11/08/15 16:01

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 8 ans 8 mois #20621 par Matthew BETTON
Salut,

Tiens... \&quot;Sogeti\&quot; ?... Etrange pseudo :whistle:

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.090 secondes
Propulsé par Kunena