日期:2014-05-16  浏览次数:20378 次

jquery 正则问题
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>测试</title>
  </head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
  var str = '<p>第一页</p>'
  +'<div style="page-break-after: always;" class="cke_pagebreak" title="分页符" contentEditable="false" data-cke-display-name="pagebreak" aria-label="分页符"></div>'
  +'<p>第二页</p>'
  +'<div style="page-break-after: always;" class="cke_pagebreak" title="分页符" contentEditable="false" data-cke-display-name="pagebreak" aria-label="分页符"></div>'
  +'<p>第三页</p>';
   
  var pattern = /<div style=\"page-break-after: always;\".*class=\"?cke_pagebreak\"?.*><\/div>/gmi;
  var arr = str.split(pattern);
  $.each(arr, function(key, val) { 
  alert(val);  
  }); 
});
</script>

大虾帮我看下为什么匹配不出第二页

------解决方案--------------------
我晕。。。你的内容少了分号。。。。要不原来的正则即可。。判断是否有分号就行了。。
DIV style="PAGE-BREAK-AFTER: always"

JScript code
    var pattern = /<div style=\"page-break-after: always;?\".*?class=\"?cke_pagebreak\"?.*?><\/div>/gi;
    var arr = str.split(pattern);
    alert(arr)