teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

ソース修正

2021/09/07 02:38

投稿

退会済みユーザー
answer CHANGED
@@ -1,6 +1,8 @@
1
1
  Python3.6(やったかな。)以降であれば
2
2
  ```diff
3
3
  - text2 = re.sub(r'\s'+delete, ' ', text)
4
- + text2 = re.sub(rf'(?<=\s)({delete})', ' ', text)
4
+ + text2 = re.sub(rf'(?<=\s)({delete})', '', text)
5
5
  ```
6
- でいけるんやないかな。[一応確認してみたで。](https://replit.com/@suwmn50799/358128Si-Wei)
6
+ でいけるんやないかな。[一応確認してみたで。](https://replit.com/@suwmn50799/358128Si-Wei)
7
+
8
+ 補足: (?<=\s)で直前の空白文字をマッチさせれば、置換後の文字列は空文字列でえかった。修正しときましたわ。

1

ソース修正

2021/09/07 02:38

投稿

退会済みユーザー
answer CHANGED
@@ -3,4 +3,4 @@
3
3
  - text2 = re.sub(r'\s'+delete, ' ', text)
4
4
  + text2 = re.sub(rf'(?<=\s)({delete})', ' ', text)
5
5
  ```
6
- でいけるんやないかな。
6
+ でいけるんやないかな。[一応確認してみたで。](https://replit.com/@suwmn50799/358128Si-Wei)