改行されていない英文を取得した際に、ピリオドで改行しようとしました。
PHPにて
$dot_pattern = "|\.{1}|i";
preg_replace($dot_pattern, ".\n", $result);
のようにしたら、例えばU.S.Aなどでも改行してしまいます。
これを、各文の終わりのみ改行したいのですが、どのようにすればいいのでしょうか?
色々と考えてみましたが、自分には無理でした。
まぁ、英文ではおそらく文末以外では大文字の後にピリオドが来るとは思うのですが。
すみませんがアドバイスを頂けないでしょうか?
No.3
- 回答日時:
横ですみません。
> 海外の方たちはどのようにして対処しているのかと思います。
海外の方たちは特に、「改行されていない文章をピリオド毎に改行する」
必要性を感じていないのでは…?
段落でまとまった文章の方が読みやすいですし。
そもそも、質問主さまはどのような目的で、ピリオドで改行なさろうと
されているのでしょうか?
その目的によって、プログラムの落としどころ
(何を実装して、何に目をつぶるか)も決まってくると思います。
No.2
- 回答日時:
ピリオドの後ろにスペースが入っていてその後大文字から始まる
という条件ならこんな感じ?
<?PHP
$str="A is a. B is b. c is C. D is d? E is e! F is f.";
$pattern="/[\.\?\!](?= [A-Z])/";
$replacement="$0\n";
$str=preg_replace($pattern,$replacement,$str);
print nl2br($str);
?>
ご回答本当にありがとうございました。
おおっ、と思って以下の文に試してみたところ、英文と言うのは()があったり、"aaaa."のような形も取るようです。
思っていたよりかなり難しいですね。
海外の方たちはどのようにして対処しているのかと思います。
The second time proved to be the charm for space engineers in the United States. They successfully launched a rocket to send an unmanned module to the International Space Station after a failed attempt three days ago.
If all goes according to plan, this will be the first private cargo delivery to the ISS.
(George Diller / NASA Launch Commentator)
"Five, four, three, two, one, zero, and launch of the SpaceX Falcon 9 rocket as NASA turns to the private sector to resupply the International Space Station."
The rocket lifted off Tuesday from an American air force base in Florida. It's carrying a spacecraft called Dragon. Engineers at the U.S.-based Space Exploration Technologies, better known as SpaceX, created it. They'll control it, too.
The module separated from the rocket about 10 minutes after liftoff. It's now orbiting the Earth, roughly 320 kilometers above the surface.
Engineers will try later this week to get the Dragon to dock at the ISS. The operation requires extreme precision because the station is orbiting the Earth at eight kilometers per second — faster than a speeding bullet.
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・14歳の自分に衝撃の事実を告げてください
- ・架空の映画のネタバレレビュー
- ・「お昼の放送」の思い出
- ・昨日見た夢を教えて下さい
- ・ちょっと先の未来クイズ第4問
- ・【大喜利】【投稿~10/21(月)】買ったばかりの自転車を分解してひと言
- ・メモのコツを教えてください!
- ・CDの保有枚数を教えてください
- ・ホテルを選ぶとき、これだけは譲れない条件TOP3は?
- ・家・車以外で、人生で一番奮発した買い物
- ・人生最悪の忘れ物
- ・【コナン30周年】嘘でしょ!?と思った○○周年を教えて【ハルヒ20周年】
- ・ハマっている「お菓子」を教えて!
- ・最近、いつ泣きましたか?
- ・夏が終わったと感じる瞬間って、どんな時?
- ・10秒目をつむったら…
- ・人生のプチ美学を教えてください!!
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・都道府県穴埋めゲーム
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
VBAのコマンドボタンの文字列の...
-
ソースコードの1行が長いとき...
-
JavaMail,本文中の改行について
-
アスキーコードへの変換につい...
-
エスケープ文字の復帰(¥r)と...
-
改行が半角スペースに変わる
-
キャリッジリターンとラインフ...
-
「続行するには何かキーを押し...
-
改行について
-
delphi でのコード上でTab を入...
-
最終行の改行について
-
JAVA System.out.println の ...
-
ダイアログにおける改行
-
C#の改行について
-
Excel VBAからBeckyを起動して...
-
秀丸の正規表現で複数行にわた...
-
1行ごとに取得して、その改行...
-
エクセルVBA 文字列領域が不足...
-
VB6のテキスト処理 さまざまな...
-
ダウンロードしたテキストを 「...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
VBAのコマンドボタンの文字列の...
-
ソースコードの1行が長いとき...
-
エスケープ文字の復帰(¥r)と...
-
エクセルVBA 文字列領域が不足...
-
C++でのCRLFについて
-
JavaMail,本文中の改行について
-
C++で空Enterの入力を判...
-
COBOLの改行
-
awkで改行を除いて文字列を抜き...
-
グレープシティのSPREAD...
-
Excel VBAからBeckyを起動して...
-
最終行の改行について
-
【VBA】エクセルで最後の不要な...
-
ファイルから読み取った改行文...
-
jsp 改行コードで改行させて表...
-
fputsで改行できない
-
改行について
-
C# DataGridViewのセルを改行禁...
-
改行を読み飛ばす
-
JavaDoc コメントの改行について
おすすめ情報