Javascript 删除带有标识符的字符串的特定部分
我有一个字符串,需要删除在Javascript 删除带有标识符的字符串的特定部分,javascript,string,typescript,Javascript,String,Typescript,我有一个字符串,需要删除在:false之后出现的第一个:familyCodes:xxxxx(始终显示:false) 例如: excludedFromIndex:false:familyCodes:13337:familyCodes:13341 应该是: excludedFromIndex:false:familyCodes:13341 有什么js函数我可以使用吗 谢谢您可以使用正则表达式来实现这一点,例如: const regEx = /:familyCodes:[\d]+/; const
:false
之后出现的第一个:familyCodes:xxxxx
(始终显示:false
)
例如:
excludedFromIndex:false:familyCodes:13337:familyCodes:13341
应该是:
excludedFromIndex:false:familyCodes:13341
有什么js函数我可以使用吗
谢谢您可以使用正则表达式来实现这一点,例如:
const regEx = /:familyCodes:[\d]+/;
const str = 'excludedFromIndex:false:familyCodes:13337:familyCodes:13341';
const result = str.replace(regEx, '');
console.log(result);
这将删除第一次出现的
:familyCodes:xxxxx:
(其中xxxxx
将匹配任意数量的数字0-9)。您可以使用正则表达式来实现这一点,例如:
const regEx = /:familyCodes:[\d]+/;
const str = 'excludedFromIndex:false:familyCodes:13337:familyCodes:13341';
const result = str.replace(regEx, '');
console.log(result);
这将删除第一个出现的
:家庭代码:xxxxx:
(其中xxxxx
将匹配任意数量的数字0-9)。替换
可能会起作用。您可以分享您迄今为止的努力吗?您在什么上下文中拥有此字符串?它是如何生成/检索的?replace
可能会起作用。您可以分享您迄今为止的努力吗?您在什么上下文中拥有此字符串?它是如何生成/检索的?