这是弹簧配置:
<bean id="wrapInMarginalMarkup" class="com.a.ChangeContentAction">
<property name="regEx">
<bean class="java.util.regex.Pattern" factory-method="compile">
<constructor-arg value="(.*)(<m>)(.*)(<xm>)(.*)" />
</bean>
</property>
<property name="replaceExpression" value="$1<marginal\.markup>$3</marginal\.markup>$5" />
</bean>
该类接受java中的参数,例如:
private Pattern regEx;
private String replaceExpression;
/**
* {@inheritDoc}
*/
@Override
public int execute(final BuilderContext context, final Paragraph paragraph)
{
String content = paragraph.getContent();
paragraph.setContent(regEx.matcher(content).replaceAll(replaceExpression));
}
这是将在模式上匹配的字符串的样子:
"Be it enacted by the Senate and House of Representatives of the United States of America in Congress assembled,,<m>Surface Transportation Extension Act of 2012.,<xm>"
它似乎并没有真正取代这里的标记,有什么问题?
我希望输出字符串看起来像:
"Be it enacted by the Senate and House of Representatives of the United States of America in Congress assembled,,<marginal.markup>Surface Transportation Extension Act of 2012.,</marginal.markup>"