我有一个由LinkedIn API返回的字符串,其中包含许多hashtag.它们的格式如下:
{hashtag|\#|somehashtag}
我try 使用一个String.replaceAll
的正则表达式,将所有出现的这些主题标签替换为标准的主题标签表示法,如下所示:
#somehashtag
我认为这个正则表达式将标识字符串中的标签,但如何标识将其替换为第二个参数的内容呢?
mystring.replaceAll(/(?<={hashtag\|\\\#\|)(.*)(?=})/g, /* whatgoeshere? */ );
例如,如果我有:
var mystring = "This is my social post, and it has a hashtag in it like this {hashtag|\#|somehashtag} and I want it replaced";
我希望能够运行以下内容:
mystring = mystring.replaceAll(regex, replacement)
因此,这将在mystring中返回:
"This is my social post, and it has a hashtag in it like this #somehashtag and I want it replaced"