Php 正则表达式删除第一次出现和第一次下一次出现
Hi搜索此代码的正则表达式版本:Php 正则表达式删除第一次出现和第一次下一次出现,php,regex,Php,Regex,Hi搜索此代码的正则表达式版本: $val = '<label for="A" >A</label><label for="B"><div>X</div></label><label for="C"><div>Y</div></label>'; $firstLabelPos = strpos($val,'<label for=
$val = '<label for="A" >A</label><label for="B"><div>X</div></label><label for="C"><div>Y</div></label>';
$firstLabelPos = strpos($val,'<label for="B">');
$sideB = substr($val,$firstLabelPos + strlen('<label for="B">') );
$firstLabelPos2 = strpos($sideB,'</label>');
$result = substr($val,0,$firstLabelPos-1)
.substr($sideB,0,$firstLabelPos2)
.substr($sideB,$firstLabelPos2+strlen('</label>'));
result : <label for="A" >A</label<div>X</div><label for="C"><div>Y</div></label>
$val='AXY';
$firstLabelPos=strpos($val',);
$sideB=substr($val,$firstLabelPos+strlen(“”));
$firstLabelPos2=strpos($sideB,');
$result=substr($val,0,$firstLabelPos-1)
.substr($sideB,0,$firstLabelPos2)
.substr($sideB,$firstLabelPos2+strlen(“”));
结果:A里面不能有另一个标签,因为根据您的规范,下一个
终止匹配(因此它不能嵌套在里面)。他不应该在里面有另一个标签。但是一些开源软件忘记了它。