【发布时间】:2013-11-11 06:14:33
【问题描述】:
我发现 123 和 321 之间的字符串并将其设为粗体。
为此,我使用 Pattern 获取 123 之前的字符串、123 和 321 之间的文本以及 321。
谁能帮我找出 123 和 321 之间的所有字符串。
下面的代码只能帮助我获得 123 和 321 的第一次出现。
Pattern p = Pattern.compile("^.*?(123)");
Matcher m = p.matcher(meredithEditorialSectionSegment);
while (m.find()) {
String desc = m.group();
String segDesc = (desc.substring(0, desc.length() - 3));
segmentDesc.add(new Chunk(segDesc, sectionDescriptionFont));
}
descBold = meredithEditorialSectionSegment.substring(meredithEditorialSectionSegment.indexOf("123") + 3);
descBold = descBold.substring(0, descBold.indexOf("321"));
segmentDesc.add(new Chunk(descBold, sectionDescriptionBoldFont));
Matcher matcher = Pattern.compile("(?<=321).*").matcher(meredithEditorialSectionSegment);
matcher.find();
segmentDesc.add(new Chunk(matcher.group(), sectionDescriptionFont));
【问题讨论】:
标签: java string pattern-matching itext string-matching