how to replace powershell text?

how to replace powershell text?
I want to write a script that get a string as an input:
PS C:\curl> $response.Content.Split(',') |Select-String -Pattern "dictionary_url_rus"

"dictionary_url_rus":"http://static.beeline.tv/catalog/translations/183011410_rus.json"

and replace "183011410_rus.json" with new paramter (file name that I read from file name:

$fromDir='C:\curl\'
$controlFileArray = Get-ChildItem $fromDir\*_rus.xml
echo $controlFileArray
Benny CaspiIntegrationAsked:
Who is Participating?
 
aikimarkCommented:
$newfile = "NotTheRus.json"
$dict = ($response.Content.Split(',') |Select-String -Pattern "dictionary_url_rus")
$dict -match "^(.+/)([^$]+)$" > null
$matches[2] = $newfile+'"'
$matches[1..2] - join ""

Open in new window

1
 
aikimarkCommented:
Or this:
$newfile = "NotTheRus.json"
$dict = ($response.Content.Split(',') |Select-String -Pattern "dictionary_url_rus")
$dict -replace "^(.+/)([^$]+)$", ('$1'+$newfile+'"')

Open in new window

Unclear whether the ending quote needs preserving.
1
 
Benny CaspiIntegrationAuthor Commented:
I get next error when I run this script:
parsing "$1201804151047_rus.xml"" - Capture group numbers must be less than or equal to Int32.MaxValue.
At line:1 char:1
+ $dict -replace "^(.+/)([^$]+)$", ('$1'+$newfile+'"')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException
0
 
aikimarkCommented:
Remove the quote character I added to the end of the replace operation.
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.