using itext how to extracta string in java

Posted by user2455183 on Stack Overflow See other posts from Stack Overflow or by user2455183
Published on 2013-10-31T09:50:43Z Indexed on 2013/10/31 9:53 UTC
Read the original article Hit count: 159

Filed under:

I am finding the string in between 123 and 321 and making it as bold. For that I used the Pattern to get the string before 123, text between 123 and 321 and text after 321. Could anyone please help me get all the strings between 123 and 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));

© Stack Overflow or respective owner

Related posts about java