一个正则表达式的问题

一个正则表达式的问题



[Copy to clipboard] [ - ]
CODE:
$_=$myecho;
s/<div\s*class=\"editor_text\">(.*?)<\/div>/$1/;
print $_;

想找出页面里的这个html标记里的内容
怎么实验都不行

$myecho内容为

[Copy to clipboard] [ - ]
CODE:
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'PaleTurquoise')
" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="co
lorContext(this, 'mouseout')"><div style="background-color: PaleTurquoise" unsel
ectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'LightBlue')" un
selectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorC
ontext(this, 'mouseout')"><div style="background-color: LightBlue" unselectable=
"on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Plum')" unselec
table="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContex
t(this, 'mouseout')"><div style="background-color: Plum" unselectable="on"></div
></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'White')" unsele
ctable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorConte
xt(this, 'mouseout')"><div style="background-color: White" unselectable="on"></d
iv></td>
</tr><tr>
<div class="editor_text">
<textarea name="message" rows="10" cols="60" style="width:99%; height:250px;font
-size:14px;font-family:Arial;padding:5px;" id="posteditor_textarea" onSelect="ja
vascript: storeCaret(this);" onClick="javascript: storeCaret(this);" onKeyUp="ja
vascript:storeCaret(this);" onKeyDown="ctlent(event);" tabindex="100"></br>
-------- Forwarded Messages --------</br>
</br>
</br><div><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin:
0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
From: &quot;test&quot; [email]test@extmail.org[/email] </br>
To: [email]testyou@111.com[/email] </br>
</br>

HOME = /home/domains/extmail.org/test<br>loginTime = 1192118532<br>OPTIONS = <br
>mailQuota = 5242880S<br>IPaddr = 192.168.1.2<br>Nosameip = 1<br>User = test@ext
mail.org<br>MAILDIR = /home/domains/extmail.org/test/Maildir/


</blockquote></div></br>

</textarea></div>

s///是替换用的,你要找出这个标记不行
你用

[Copy to clipboard] [ - ]
CODE:
/<div\s*class=\"editor_text\">(.*?)<\/div>/ and print $1;

不过结果还不是你要的,结果大概是

[Copy to clipboard] [ - ]
CODE:
<textarea name="message" rows="10" cols="60" style="width:99%; height:250px;font
-size:14px;font-family:Arial;padding:5px;" id="posteditor_textarea" onSelect="ja
vascript: storeCaret(this);" onClick="javascript: storeCaret(this);" onKeyUp="ja
vascript:storeCaret(this);" onKeyDown="ctlent(event);" tabindex="100"></br>
-------- Forwarded Messages --------</br>
</br>
</br><div><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin:
0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
From: &quot;test&quot; [email]test@extmail.org[/email] </br>
To: [email]testyou@111.com[/email] </br>
</br>

HOME = /home/domains/extmail.org/test<br>loginTime = 1192118532<br>OPTIONS = <br
>mailQuota = 5242880S<br>IPaddr = 192.168.1.2<br>Nosameip = 1<br>User = test@ext
mail.org<br>MAILDIR = /home/domains/extmail.org/test/Maildir/


</blockquote></div></br>

</textarea>

因为正则表达式是贪婪的,你还得改下匹配模式,进行最小匹配
可能是因为有换行把,"."一般情况下是不匹配换行的,需要加上s修饰符
s/<div\s*class=\"editor_text\">(.*?)<\/div>/$1/s;
谢谢楼上2位,解决啦~~~

的确是需要作为单行处理就是s修饰,另外就是贪婪模式

非常感谢