Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 正则表达式-将HTML标记(和内容)与内部相同的标记匹配_Java_Html_Css_Regex - Fatal编程技术网

Java 正则表达式-将HTML标记(和内容)与内部相同的标记匹配

Java 正则表达式-将HTML标记(和内容)与内部相同的标记匹配,java,html,css,regex,Java,Html,Css,Regex,我有一根这样的绳子 <some other tags and things> <span style="color: #e23d39;"><strong><span style="color: #2873ee;">Some Text</span></strong></span> <some other tags and things> 在第一次运行中,需要: <span style="colo

我有一根这样的绳子

<some other tags and things> <span style="color: #e23d39;"><strong><span style="color: #2873ee;">Some Text</span></strong></span> <some other tags and things>
在第一次运行中,需要:

<span style="color: #e23d39;"><strong><span style="color: #2873ee;">Some Text</span>
一些文本
在另一部分之外:

</strong></span>


那么什么是正确的正则表达式,或者我如何修复它呢?

无论您在哪里找到
(?:.|\n)*?
模式,都要知道这是我见过的最糟糕的模式之一。HTML必须用HTML解析器来解析。你能把你想要得到的和你正在得到的都包括进去吗?我是在寻找有无换行符的匹配时发现的。g、 e.(此处换行\n)asdasd HTML不是一种常规语言,因此不能用正则表达式表示。唯一合理的解决方案是使用真正的解析器。
<font color="#e23d39"><strong><font color= "#2873ee">Some Text</font></strong></font>
/<span\s*?style="(.*?)">((?:.|\n)*?)<\/span>/g
<span style="color: #e23d39;"><strong><span style="color: #2873ee;">Some Text</span>
</strong></span>