且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

RegEx在HTML标记之间提取文本

更新时间:2022-11-14 22:56:40

您的评论显示您忽略了逃避正则表达式字符串中的反斜杠。

Your comment shows that you have neglected to escape the backslashes in your regex string.

如果你想匹配小写字母,请将 az 添加到字符类或使用 Pattern.CASE_INSENSITIVE (或将(?i)添加到正则表达式的开头)

And if you want to match lowercase letters add a-z to the character classes or use Pattern.CASE_INSENSITIVE (or add (?i) to the beginning of the regex)

"<([A-Za-z][A-Za-z0-9]*)\\b[^>]*>(.*?)</\\1>"

如果标签内容可能包含换行符,则使用 Pattern.DOTALL 或将(?s)添加到正则表达式的开头以打开dotall / singleline模式。

If the tag contents may contain newlines, then use Pattern.DOTALL or add (?s) to the beginning of the regex to turn on dotall/singleline mode.