使用js如何将你好#2#我的#3#世界#1#取出# #
您好,以下是使用JavaScript将字符串中的特定部分取出的示例代码:
const str = '你好{#2#}我的{#3#}世界{#1#}取出{# #}';
// 使用正则表达式匹配出{# #}之间的内容
const regex = /\{(#\d+#)\}/g;
const matches = str.match(regex);
// 提取出匹配到的内容
const extractedValues = matches.map(match => match.substring(2, match.length - 2));
console.log(extractedValues);
运行以上代码,将会输出 ["2", "3", "1"],即成功提取了字符串中的 {#2#}、{#3#} 和 {#1#} 中的数字。
原文地址: https://www.cveoy.top/t/topic/h6hx 著作权归作者所有。请勿转载和采集!