【问题标题】:Write code in return statement, add dot to string在返回语句中编写代码,将点添加到字符串
【发布时间】:2016-03-01 00:55:20
【问题描述】:

你能帮我写一个代码,它在字符串“\n”中看到就会用“\n\t\t\t”替换它,并在p之后添加一个点。 从实际文本 = "\t\tp\nLorem ipsum\nMid magnis\nTristique mauris proin" 到 预期:“\t\tp。\n\t\t\tLorem ipsum\n\t\t\tMid magnis\n\t\t\tTristique mauris proin”

我知道替换我可以使用 text.replace(/(?:\n)/g, "\n\t\t\t") 但如何在 p 之后添加点。因为所有这些操作都必须在一次返回语句中执行。

谢谢!

【问题讨论】:

    标签: javascript string replace return


    【解决方案1】:

    试试

    var res = text.replace(/(\n)/g, "$1\t\t\t").replace(/(p)/g, "$1.")
    

    【讨论】:

      猜你喜欢
      • 2018-07-06
      • 2023-03-20
      • 2011-04-15
      • 1970-01-01
      • 2018-03-08
      • 2021-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多