rtf でドキュメント ワークフローを処理するシステムがあります。標準のRtfでうまく機能します。そして、Word 2003でそれを処理できる正規表現を知っています.Word 2007を処理できるようにしたい.
私のタグは次のようになります: [[FooBuzz]]。
ワードパッドのような多くのプログラムは、[[FooBuzz]] を平文で保持します。Word 2003 は [[ をタグから分解します。Word 2007 はさらに最悪で、大文字のたびに爆発します。だからフー・バズ。
私のサンプルデータ:
{ toto}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5517131 [[}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid2708730 Foo}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid2708730 Buzz}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5517131 ]]} {toto}
私は2つのことが必要です。[[FooBuzz]] の rtf 表現に一致する最初の正規表現
例: {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5517131 [[}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid2708730 Foo}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid2708730 バズ}{\ rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5517131 ]]}
次に、タグの名前を選択します。ここでFooBuzz。PHP 関数 preg_match_all を使用する必要があります。
したがって、これはテストデータを doublelinc したテスト結果です。
Array
( [0] => 配列 ( [0] => {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5517131 [[}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid2708730 Foo}{\rtlch\fcs1 \ af0 \ltrch\fcs0 \insrsid2708730 バズ}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5517131 ]]} [1] => {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5517131 [[}{\rtlch\ fcs1 \af0 \ltrch\fcs0 \insrsid2708730 Foo}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid2708730 バズ}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5517131 ]]} )
[1] => Array
(
[0] => {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5517131 [[}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid2708730 Foo}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid2708730 Buzz}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5517131 ]]}
[1] => {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5517131 [[}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid2708730 Foo}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid2708730 Buzz}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5517131 ]]}
)
[2] => Array
(
[0] =>
[1] =>
)
[3] => Array
(
[0] => Foo
[1] => Foo
)
)
ご覧のとおり、必要に応じてタブが生成されます。キー 1 は、後で処理するバグです。[[FooBuzz]] が展開されていない場合のみ、キー 2 が結果として表示されます。キー 3、単語 2003 を使用した結果として。
したがって、Foo と Buzz は異なる配列にある可能性があります。一貫性がある限り、それで十分です。
例 :
[3] => Array
(
[0] => Foo
)
[4] => Array
(
[0] => Buzz
)
また
[3] => Array
(
[0] => FooBuzz
)
受け入れられた答えです。
私の正規表現と彼の説明:
それを構築するためのスタックオーバーフローに関するヘルプを受け取りました:
/(\[\[([^\[\]]*?)\]\]|{[^{]*?\[\[.*?(?<=\[\[).+?\b(?<!\\)(\w+)\b(?=.+?\]\]).*?\]\].*?})/
より意味のある方法で:
/( Begenning of the OR clause
\[\[([^\[\]]*?)\]\] Regex used to catch [FooBuzz] in plain text.
| Or statement.
{[^{]*?\[\[.*?(?<=\[\[).+? Part able to catch the Rtf translation of [[
\b(?<!\\)(\w+)\b This part have a negative look behind. It match rtf metadata (ex \toto123. And i selects Foo
(?=.+?\]\]).*?\]\].*?} Match the RTF translations of ]]
)/ End of or statement.
注 : 貪欲ではない文字 (?) がたくさんあります。このように、正規表現は必要に応じてタグとそのメタデータのみを選択します。(プレーンテキストに置き換えます)。
これはレガシー コードです。プレーン テキストの方法を放棄することはできません。パフォーマンスは問題ではありません。バッチで実行されます。
どうやって FooBuzz をキャッチしますか?
テスト サイト :
http://www.spaweditor.com/scripts/regex/index.php preg_match_all の出力を表示します。
http://rubular.com/r/5fm7afU5vG パーマリンクを編集できるので、もっと楽しく使えます。ご覧のとおり、一致はターゲット関数と同じ方法で表示されます。
手短に :
I want to match all the RTF reprsentation of [[FooBuzz]] with match 1.
I want either match x => FooBuzz or match x => Foo match x + 1 => Buzz, if consistent.
別の Or を自由に追加できます。それ以外の場合、編集する部分は \b(?