Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
regex Replace
#1
Hi,

I would like to know the equivalent code for the PowerShell code below, I use this method a lot

The C# method is as follows
https://learn.microsoft.com/en-us/dotnet...em-string)

PowerShell code is a little more elegant to implement, However, sometimes I need to implement it in QM

Thanks in advance for any advice and help
david
 
Code:
Copy      Help
$s = @'
bbbbb2
aaaaa4


@hello
hello

@world
world
'@
$a = 'ABC'

[regex]::Replace($s, '(?s)^[^@]+', {
        $av = $args.Value
        if ([string]::IsNullOrEmpty($av.Trim())) { return $av }
        [int[]]$num = [regex]::Matches($av, '\d+').Value
        $n = 1
        while ($true)
        {
            if ($num -ne $null -and $num.Contains($n)) { $n++ }
            else { break }
        }
        return "{0}`r`n$a$n`r`n`r`n" -f $av.TrimEnd()
    })


Messages In This Thread
regex Replace - by Davider - 11-29-2022, 06:35 AM
RE: regex Replace - by Davider - 11-29-2022, 09:43 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)