Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我尝试替换两个评论之间的字符串,如下所示:
<span>Just <!--{-->250<!--}--> characters available!</span>
我想250用另一个号码替换。
250
我怎样才能做到这一点?
试试这个正则表达式:
text.replace(/(<!--\{-->)(\d+)(<!--\}-->)/, '$1replaced$3'));
我不确定确切的 javascript 语法,但以下内容应该只匹配数字(这就是你想要的,对吗?你只想替换“250”?)
(?<=<!\-\-\{\-\->)\d+(?=<\!\-\-\}\-\->)