正则表达式匹配 php - < >和换行符/回车符之间的所有字符



我试图让正则表达式匹配< >之间的所有文本,包括换行符和回车符。

我走得最远的是:(<.*>)|(<.*n)

我正在测试的正则表达式101字符串在这里:https://regex101.com/r/wuFeG9/1

如您所见,它匹配< >之间的所有文本大小写,除非中间有回车符/换行符 - 组 2 的红色突出显示显示它中断的位置。

我不足的地方是当< >括号内有换行符/回车符时。 我无法s匹配它,即使记事本++中的文本显示那里有回车符。

任何帮助将不胜感激!
提前谢谢。

你可以使用

<[^>]*>

这里的[^>]的意思是"除>以外的任何字符"。这是一个字符类。


请注意,如果你想解析 HTML,而不仅仅是盲目地搜索和替换,正则表达式不是一个好方法。此外,正则表达式不能干净地处理损坏的 HTML。请参阅如何在 PHP 中解析和处理 HTML/XML?正确的方法。

这应该有效

正则表达式:

((?:<.*>)|(?<=>)(?:<.*n?.*>))

PHP代码:

$re = '/((?:<.*>)|(?<=>)(?:<.*n?.*>))/m';
$str = '<p><font face="Helv" size="2"><font face="Helv" size="2">- $25mm to $50mm near term GLRV opportunity. If approved, they would invest in our commingled
fund.</font></font><br><font face="Helv" size="2"><font face="Helv" size="2">- This was another critical step in Investcorp&#39;s investment process. In a
positive sign, they&#39;ve decided to concurrently initiate operational due diligence on us and the GLRV fund/strategy.</font></font><br><font face="Helv"
size="2"><font face="Helv" size="2">- Overall an excellent, interactive meeting mainly focused on risk modeling and measurement, and how we use our 
models/tools throughout the investment process to help source and implement trades; actively allocate risk across sub-strategies; as well as adjust the overall risk
taking in the strategy</font></font></p>
MEETING DETAILS:
None Available
NOTES:
<p><font face="Helv" size="2"><font face="Helv" size="2">- Investcorp is a NY based $10 billion global alternative investments manager with roots and a large
presence in the middle east.</font></font><br><font face="Helv" size="2"><font face="Helv" size="2">- They are running ~$2 billion in traditional FoHFs AUM (in
addition to another $2 billion in other custom HF mandates) after closing on their SSARIS Advisors (another FoHFs) acquisition earlier this
year.</font></font><br><font face="Helv" size="2"><font face="Helv" size="2">- The consolidation of their portfolio continues following the SSARIS acquisition
and he team is finally ready to allocate to new managers. FI Arb/RV is a space they are interested in again.</font></font><br><font face="Helv" size="2"><font
face="Helv" size="2">- We have the advantage of being &quot;first in the door&quot; as they assessed the space, since we&#39;ve been talking to them about LRV
since early 2014.</font></font><br><font face="Helv" size="2"><font face="Helv" size="2">';
preg_match_all($re, $str, $matches);
// Print the entire match result
print_r($matches);

输入:

<p><font face="Helv" size="2"><font face="Helv" size="2">- $25mm to $50mm near term GLRV opportunity. If approved, they would invest in our commingled
fund.</font></font><br><font face="Helv" size="2"><font face="Helv" size="2">- This was another critical step in Investcorp&#39;s investment process. In a
positive sign, they&#39;ve decided to concurrently initiate operational due diligence on us and the GLRV fund/strategy.</font></font><br><font face="Helv"
size="2"><font face="Helv" size="2">- Overall an excellent, interactive meeting mainly focused on risk modeling and measurement, and how we use our 
models/tools throughout the investment process to help source and implement trades; actively allocate risk across sub-strategies; as well as adjust the overall risk
taking in the strategy</font></font></p>
MEETING DETAILS:
None Available
NOTES:
<p><font face="Helv" size="2"><font face="Helv" size="2">- Investcorp is a NY based $10 billion global alternative investments manager with roots and a large
presence in the middle east.</font></font><br><font face="Helv" size="2"><font face="Helv" size="2">- They are running ~$2 billion in traditional FoHFs AUM (in
addition to another $2 billion in other custom HF mandates) after closing on their SSARIS Advisors (another FoHFs) acquisition earlier this
year.</font></font><br><font face="Helv" size="2"><font face="Helv" size="2">- The consolidation of their portfolio continues following the SSARIS acquisition
and he team is finally ready to allocate to new managers. FI Arb/RV is a space they are interested in again.</font></font><br><font face="Helv" size="2"><font
face="Helv" size="2">- We have the advantage of being &quot;first in the door&quot; as they assessed the space, since we&#39;ve been talking to them about LRV
since early 2014.</font></font><br><font face="Helv" size="2"><font face="Helv" size="2">

输出:

Array
(
    [0] => Array
        (
            [0] => <p><font face="Helv" size="2"><font face="Helv" size="2">
            [1] => </font></font><br><font face="Helv" size="2"><font face="Helv" size="2">
            [2] => </font></font><br>
            [3] => <font face="Helv"
size="2"><font face="Helv" size="2">
            [4] => </font></font></p>
            [5] => <p><font face="Helv" size="2"><font face="Helv" size="2">
            [6] => </font></font><br><font face="Helv" size="2"><font face="Helv" size="2">
            [7] => </font></font><br><font face="Helv" size="2"><font face="Helv" size="2">
            [8] => </font></font><br><font face="Helv" size="2">
            [9] => <font
face="Helv" size="2">
            [10] => </font></font><br><font face="Helv" size="2"><font face="Helv" size="2">
        )
    [1] => Array
        (
            [0] => <p><font face="Helv" size="2"><font face="Helv" size="2">
            [1] => </font></font><br><font face="Helv" size="2"><font face="Helv" size="2">
            [2] => </font></font><br>
            [3] => <font face="Helv"
size="2"><font face="Helv" size="2">
            [4] => </font></font></p>
            [5] => <p><font face="Helv" size="2"><font face="Helv" size="2">
            [6] => </font></font><br><font face="Helv" size="2"><font face="Helv" size="2">
            [7] => </font></font><br><font face="Helv" size="2"><font face="Helv" size="2">
            [8] => </font></font><br><font face="Helv" size="2">
            [9] => <font
face="Helv" size="2">
            [10] => </font></font><br><font face="Helv" size="2"><font face="Helv" size="2">
        )
)

请参阅:https://regex101.com/r/wuFeG9/2

测试 PHP 代码:http://ideone.com/2B5n3o

最新更新