特定のスタイルでフォーマットしたい文字列 (テキスト、数字、句読点など) があります。
私はこれを持っています:
1. TOC 1.1 Chapter 1.1 1.2 Chapter 1.2 1.3 Chapter 1.3 2. Automation 2.1 This is Chapter 2.1 2.2 Chapter 2.2 is it's name 3. Mechanics 3.1 Chapter 3.2 Some Chapter 3.2a Sub-chapter of 3.2 3.2b Sub-chapter of 3.2 chapter
これが必要です:
1. TOC
1.1 Chapter 1.1
1.2 Chapter 1.2
1.3 Chapter 1.3
2. Automation
2.1 This is Chapter 2.1
2.2 Chapter 2.2 is it's name
3. Mechanics
3.1 Chapter
3.2 Some Chapter
3.2a Sub-chapter of 3.2
3.2b Sub-chapter of 3.2 chapter
これを試しました:
$text = preg_replace('/([0-9])/', "\n\t$1", $text);
これを取得しました(間違った出力):
1. TOC
1.
1 Chapter
1.
1
1.
2 Chapter
1.
2
1.
3 Chapter
1.
3
2. Automation
2.
1 This is Chapter
2.
1
2.
2 Chapter
2.
2 is it's name
3. Mechanics
3.
1 Chapter
3.
2 Some Chapter
3.
2a Sub-chapter of
3.
2
3.
2b Sub-chapter of
3.
2 chapter
出力が必要な形式で表示されるようにするには、どうすれば修正できますか?