每当一个字符串包含一个大写字母后跟一个句点时,我想用大写字母替换大写字母和句点。
Today MR. Johnson walked to the mail box.
=> Today MR Johnson walked to the mail box.
William SR. won the race.
=> William SR won the race.
我尝试使用以下方法完成此操作gsub
:
MyText = "William SR. won the race."
MyText = MyText.gsub(/[A-Z]\./,**I DON'T KNOW WHAT TO PUT HERE**]
我可以匹配句点后面的大写字母,但我不知道如何用句点前面的大写字母替换我的匹配项。