How to use Android REGEX with Pattern and Matcher Classes?

…衆ロ難τιáo~ 提交于 2019-12-05 12:17:47

By default, the . does not match line breaks. You would need to add a regex option so that it does:

Pattern p = Pattern.compile(myPattern,Pattern.DOTALL);

m.matches() will only return true if the entire string matches. Use m.find() instead, and it should work better!

First, as arc has said, . won't match to \n unless you activate Pattern.DOTALL, and as Petter M, you should use m.find(), or else it won't match.

Then, you could use this other expression, if, by any reason, you cannot work with Pattern.DOTALL.

FILES_SECTION(?:.|\s)*FILES_SECTION

(Note I'm using a non-capturing group for the characters between the FILES_SECTION delimiters).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!