我有以下正则表达式:
(<div class="dotted-highlight">(.*?)\s*){2,}<ul>
匹配以下字符串:
<div class="dotted-highlight">The cover letter should include:
<div class="dotted-highlight"><ul>
我需要访问The cover letter should include
,所以我尝试了:
<?php
$textarea = '<div class="dotted-highlight">The cover letter should include:
<div class="dotted-highlight"><ul>';
$replacing_to = '(<div class="dotted-highlight">(.*?)\s*){2,}<ul>';
$replacing_with = '$1<ul>';
$textarea = preg_replace('#'.$replacing_to.'#', $replacing_with, $textarea);
?>
$replacing_with
添加<div class="dotted-highlight">
而不是所需的文字:The cover letter should include:
所以输出结果为:
<ul>
和预期的输出将是:
The cover letter should include: <ul>
FIDDLE:
REGEX TESTER