Martin Erlic
Martin Erlic

Reputation: 5667

Unable to compile pattern matching program for list

I'm trying to build a list and increment a counter for each list item that has a particular keyword. I'm unable to compile this. Why?

        int count = 0;
        String keyword = args[1];

        Pattern p = Pattern.compile(keyword);
        Matcher m = p.matcher(p);

        /* For each paragraph in the document... */
        for (XWPFParagraph paragraph : paragraphs) {
            /* Add to List */
            words.add(paragraph.getText());
            System.out.println(paragraph);

            /* Iterate keyword count */
            while (m.find()) {
                count++;
            }
        }

Upvotes: 0

Views: 36

Answers (1)

Sharon Ben Asher
Sharon Ben Asher

Reputation: 14373

The problem is probably here

Matcher m = p.matcher(p);

the argument should be the text to search

Matcher m = p.matcher(paragraph.getText());

Upvotes: 1

Related Questions