-1
これは私のコードスニペットですが、これは基本的なものです。私はベンチャーを正規表現に始めている。私が以下を実行すると、すべて正常に動作しますが、ハイフンと文字列の置換の間のギャップをどのように埋めるかを知りたいと思います。 「8時間の日」は「8日のBOOGIEの日」となり、そのスペースを閉じたいと思う。助けてください!python regex - re.subの前に空白を削除
import re
short_par = 'You must pace your work. What do I mean? I’m glad you asked that. We pace our work according to the eight-hour workday. If you have twelve hours of work in your in-box, for example, you must compress that work into the eight-hour day. If you have one hour of work in your in-box, you must expand that work to fill the eight- hour day. That was a good question. Feel free to ask questions. Ask too many questions, however, and you may be let go.'
regex = re.compile('[hy]our')
print(regex.sub('BOOGIE', short_par))
SOコミュニティを尊重し、MINIMALの例を投稿してください。長い 'short_par'文字列全体はあなたの問題を説明するために必要ではありませんが、' '8時間の' '場所を見つけるために水平にスクロールしなければなりません。 – DyZ
私はあなたが 're.sub'でも使いたいと思うことができると思います。あなたはそれを理解することができるはずです。 –
非常に非常に有用な、皆、洞察力のおかげです。 –