【发布时间】:2020-01-29 06:10:56
【问题描述】:
如何替换某个字符之后的任何内容?例如:
var temp = 'abcdefghikj';
我想将c之后的所有字符都替换为空:
temp.replace('c*', '');
我查看了这个主题,但没有一个建议的解决方案对我有用: Regular Expressions- Match Anything
【问题讨论】:
-
temp = temp.substring(0, temp.indexOf("c") + 1); -
我不知道我做错了什么,但表达式
\?(.*)对我不起作用。在我的情况下,我需要将其编辑为\c(.*)或\c.*,但在temp.replace('\c.*', '');中使用时它不起作用
标签: javascript regex