this code only replaces the last instance in a string, is there anyway to have it work on all instances in the string?
if ($syllableCount -ge 2 -and $lastthree -eq 'ing') {
$newWord = $word -replace "ing$", "in'"
$newWord
}
else {
$word
}
output:
.\friar.ps1 -words 'Doing making going'
Doing making goin'
PS – I am working on Doug Finkes Tiny-Powershell-Projects challenges, they are alot of fun.
text
if ($syllableCount -ge 2 -and $lastthree -eq 'ing') {
$newWord = $word -replace "ing$", "in'"
$newWord
}
else {
$word
}
actual output:
.\friar.ps1 -words 'Doing making going'
Doing making goin'
Would like to see:
Doin' makin' goin'
>Solution :
Your regex just needs a tiny modification to make it work, change $ (end of string) for \b (matches a word boundary) then it should work:
'Doing making going' -replace 'ing\b', "in'"
See https://regex101.com/r/KCIHRc/1 for regex details.