从rtf标签中提取原始字符串

时间:2014-08-16 10:25:27

标签: regex rtf

正则表达式,用于从以下标记中提取原始文本

{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid9392958\charrsid9392958 This Sentence is in Calibri with font 11.}

需要提取此句子在Calibri中使用字体11.

{\rtlch\fcs1 \af0 \ltrch\fcs0 \cf17\highlight7\insrsid11236687  with blue font and yello}

需要使用蓝色字体和yello

提取

我写正则表达式\{\\rtlch\\fcs1.*但它匹配完整的字符串。 我想要只与原始文本匹配的正则表达式。

1 个答案:

答案 0 :(得分:0)

执行此操作的一种方法是使用以下表达式:

(?:\{\\rtlch\\fcs1 \\\S* \\\S* \\\S*\s*)(.*)(?=\})

此表达式允许您仅捕获第二组,第一组是\rtlch\\fcs1 \\\S* \\\S* \\\S*\s*(即您要避免的部分)。

您可以在regex101上验证。

要匹配{\rtlch\fcs1 \af0 \ltrch\fcs0 \f39\insrsid9392958 arial black with font 11.\par \ltrrow}{\rtlch\fcs1 \af0 \ltrch\fcs0 \i\insrsid9392958\charrsid9392958 This Sentence is in Calibri with font 11.\par }等表达式(如评论中所述),您可以使用:

(?:\{\\rtlch\\fcs1 \\\S* \\\S* \\\S*\s*)([^\\\}]*)

链接到regex101 for the second expresion

注意:您可能会添加一个积极的预测,例如(?=\}|\\),但我不知道您是否需要它。