代码如下:
processName:"测试测试(12/12)"
期望 截取到测试测试
function getProcessName(str) {
var startIndex = str.indexOf(':') + 1;
var endIndex = str.indexOf('(');
return str.substring(startIndex, endIndex);
}
var processName = '测试测试(12/12)';
console.log(getProcessName(processName)); // Output: 测试测试
用GPT啊
1.用正则表达式的 exec 方法:
const regex = /(.+)(?=\()/;
const processName = "测试测试(12/12)";
const result = regex.exec(processName);
console.log(result[1]); // 输出: 测试测试
2.用 split 方法:
const processName = "测试测试(12/12)";
const result = processName.split('(')[0];
console.log(result); // 输出: 测试测试
13 回答12.8k 阅读
8 回答2.5k 阅读
2 回答5k 阅读✓ 已解决
3 回答2.2k 阅读✓ 已解决
5 回答817 阅读
3 回答2.1k 阅读
5 回答1.1k 阅读✓ 已解决