【发布时间】:2015-08-06 18:52:07
【问题描述】:
我有一个这样的降价字符串:
var str = "
# Title here
Some body of text
## A subtitle
##There may be no space after the title hashtags
Another body of text with a Twitter #hashtag in it";
现在我想匹配并替换所有标题主题标签,以向它们添加另一个主题标签。但我需要避免匹配文本行中的主题标签(推特主题标签)。我正在尝试实现以下字符串:
var str = "
## Title here
Some body of text
### A subtitle
###There may be no space after the title hashtags
Another body of text with a Twitter #hashtag in it";
到目前为止,我已经有了这个正则表达式,它可以完成这项工作,但也与 twitter 主题标签匹配:
str = str.replace(/(#+)/g, "$1#");
每行文本后面都有回车符。如何在不影响文本中的主题标签的情况下实现此替换。
【问题讨论】:
-
你的
var str = ...是一个有效的JS语法吗? -
@anubhava 肯定不是。
标签: javascript regex replace markdown