下図のような電子書籍など、なんでもいいのですがテキストにコピペしたときに改行されない場合があります。
Contents Title Page Copyright Epigraph Introduction: My Story The Fundamentals Why Tiny Changes Make a Big Difference 1 The Surprising Power of Atomic Habits 2 How Your Habits Shape Your Identity (and Vice Versa) 3 How to Build Better Habits in 4 Simple Steps The 1st Law Make It Obvious 4 The Man Who Didn’t Look Right 5 The Best Way to Start a New Habit 6 Motivation Is Overrated; Environment Often Matters More 7 The Secret to Self-Control The 2nd Law Make It Attractive 8 How to Make a Habit Irresistible 9 The Role of Family and Friends in Shaping Your Habits 10 How to Find and Fix the Causes of Your Bad Habits
これの見出しの数字を改行して整形したい場合、数字を探してクリックしてEnterで改行してと、チマチマした作業が発生します。これを正規表現で実行するには以下のように対応します。
法則的には
[数字のあとに半角スペース]が見出しの数字となっていそうです。
置換前:(\d+ )
置換後:\r\n$1
とします。
()でくくると、グループという概念でひとまとまりになります。
\dは数字を意味します
+は直前(左)の文字を1文字以上が該当
「 」←半角スペース
\r\nはWindowsの場合とりあえず改行として指定してます。
$1というのはグループの1番目を意味します。
実行した結果は以下のとおりです。
Contents Title Page Copyright Epigraph Introduction: My Story The Fundamentals Why Tiny Changes Make a Big Difference
1 The Surprising Power of Atomic Habits
2 How Your Habits Shape Your Identity (and Vice Versa)
3 How to Build Better Habits in
4 Simple Steps The 1st Law Make It Obvious
4 The Man Who Didn’t Look Right
5 The Best Way to Start a New Habit
6 Motivation Is Overrated; Environment Often Matters More
7 The Secret to Self-Control The 2nd Law Make It Attractive
8 How to Make a Habit Irresistible
9 The Role of Family and Friends in Shaping Your Habits
10 How to Find and Fix the Causes of Your Bad Habits
ちなみに、加工している対象は「Atomic Habits」、日本語では「ジェームズ・クリアー式 複利で伸びる1つの習慣」という書籍です。
0 件のコメント:
コメントを投稿