Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
foreach and replace nested
#1
Hi,

I want to know the blue word section (powershell code) with the same effect as the QM code,

foreach and replace nested

Thanks in advance for any advice and help
david
________________________________________________________________________________
$s = @'
function A([Paragraph]$p1, [Paragraph]$p2){
    '{A}'
}
function BB([Paragraph]$p1){
    '{BB}'
}
function CCC(){
    '{CCC}'
}

function Main([string[]]$args)
{
    $A($p1, $p2)
    $BB($p1)
    $CCC()
}
'@

$b = $s | Select-String 'function ([a-zA-Z_][a-zA-Z0-9_]*\().*\)' -AllMatches |
foreach{
    $_.Matches |
    foreach{
        '${0}' -f $_.Groups[1].Value
    }
}


$s -split '\r?\n' |
foreach {
    foreach ($b_ in $b)
    {
        if ($_ -match [regex]::Escape($b_))
        {
            $_ = $_ -replace '\(', ' ' -replace '\)' -replace ',' -replace '^(\s*)\$','$1'
        }
    }
    $_
}


Messages In This Thread
foreach and replace nested - by Davider - 10-23-2022, 07:57 AM
RE: foreach and replace nested - by Davider - 10-23-2022, 11:45 AM
RE: foreach and replace nested - by Gintaras - 10-23-2022, 11:58 AM
RE: foreach and replace nested - by Davider - 10-23-2022, 12:00 PM
RE: foreach and replace nested - by Gintaras - 10-23-2022, 12:05 PM
RE: foreach and replace nested - by Davider - 10-23-2022, 12:14 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)