我有以下声明,
sentence = " Hi my goal is to achieve highest score in mathematics, but my friend has scored some how more. and now i am myself depressed.
我想将所有“ my”替换为“ PRONOUN”,如下所示。我不想替换自己,是我自己要保持现状
预期输出为:
Hi PRONOUN goal is to achieve highest score in mathematics, but PRONOUN friend has scored some how more. and now i am myself depressed.
我已经尝试过在python中使用regex
regex = re.sub(r'\\bmy$')
答案 0 :(得分:6)
您非常亲密。在开始和结束处使用边界。
例如:
$Constant = "somestring"
$Strings = Get-Content ".\strings.txt"
for($i=0;$i -lt $Strings.count;$i++) {
$Strings[$i] += $Constant
}
$Strings
输出:
onesomestring
twosomestring
threesomestring