0

我已经成功提取了下面的 JSON,但是在将那些讨厌的正则表达式 \r\n\r\n 转换为<br/>'s 时遇到了问题。我目前正在使用以下代码,但它只转义了一些。我正在寻找替换正则表达式的所有实例,包括:\r\n、\r\n\r\n。我之前使用的代码是:

$('<ul class="job-listing"><li class="job-position"><h2>'+post.m_positionName+'</h2></li><li class="job-description">'+post.m_description.replace('\r\n','<br />')+'</li></ul>').appendTo('body');

这是JSON:

[
  {
    "m_id": 473644,
    "m_positionName": "Application Monitoring Software Engineer",
    "m_positionLocations": [
      {}
    ],
    "m_active": true,
    "m_description": "Job Responsibilities:\r\n\r\n-Create world class application monitoring tools and dashboards for our health care applications\r\n\r\n-Develop business rules to pro actively identify and re-mediate system-level issues before they occur.\r\n\r\n-Create business intelligence reports for internal and external use as a supplement to software products.\r\n\r\n\r\n\r\nJob Requirements:\r\n\r\n-BS or MS Degree in computer science or any engineering discipline.\r\n-4+ years of experience with Java (or other object-oriented programming language).\r\n-Experience in SQL, Struts, Hibernate, Spring, Eclipse, JSP, JavaScript.\r\n-Highly motivated and self-driven personality.\r\n-Excellent interpersonal and leadership skills.\r\n-A vision for the future and a desire to make a difference.\r\n-Experience with Maven, Tomcat, PostgreSql, Jasper Reports,",
    "m_postedDate": "Jun 29, 2012 9:17:19 AM",
    "m_closingDate": "Jun 29, 2013 12:00:00 AM"
  }
4

2 回答 2

6

用这个:

post.m_description.replace(/\r\n|\n|\r/g, '<br />');
于 2012-11-21T14:48:17.633 回答
1

尝试这个:

replace(/\r\n/, '<br/>')

JS中的正则表达式不需要用引号封装

于 2012-11-21T14:48:38.597 回答