Java Find word in a String

后端 未结 5 1230
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-15 10:25

I need to find a word in a HTML source code. Also I need to count occurrence. I am trying to use regular expression. But it says 0 match found.

I am using regular ex

5条回答
  •  春和景丽
    2021-01-15 11:31

    You are not matching any "expression", so probably a simple string search would be better. commons-lang has StringUtils.countMatches(source, "yourword").

    If you don't want to include commons-lang, you can write that manually. Simply use source.indexOf("yourword", x) multiple times, each time supplying a greater value of x (which is the offset), until it gets -1

提交回复
热议问题