我正在尝试使用正则表达式匹配<
>
之间的所有文本,包括换行符和回车符。
(<.*>)|(<.*\n)
我正在测试的Regex101字符串位于:https://regex101.com/r/wuFeG9/1
正如您所看到的,它匹配<
>
之间的所有文本情况,除非中间有回车符/换行符 - 组2的红色高亮显示其中断的位置。
当我在<
>
括号内有换行符/回车符时,我就会失败。我无法让\s
与之匹配,即使notepad ++中的文字显示那里有回车符。
任何帮助将不胜感激!!
提前谢谢。
答案 0 :(得分:3)
您可以使用
<[^>]*>
此处[^>]
表示“>
以外的任何字符”。这是一个角色类。
请注意,如果要解析HTML,而不是盲目搜索和替换,则regex不是一个好方法。此外,正则表达式无法干净地处理损坏的HTML。请参阅How do you parse and process HTML/XML in PHP?了解正确的方法。
答案 1 :(得分:-1)
这应该有用
<强> REGEXP:强>
((?:<.*>)|(?<=>)(?:\<.*\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's investment process. In a
positive sign, they'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 "first in the door" as they assessed the space, since we'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);
<强> INPUT:强>
<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's investment process. In a
positive sign, they'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 "first in the door" as they assessed the space, since we'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