Javascript 如何使用正则表达式从基于泛型类型的字符串中删除完整的行

Javascript 如何使用正则表达式从基于泛型类型的字符串中删除完整的行,javascript,regex,Javascript,Regex,如果有一个参数的值为Window:String const str = `fnct1(param: Int, Window: String): String func2(Window: String): String function3(param: String): String`; const regex = /[^\s(]+\(Window:\s*String\): [^(\s]+\s*/gm; const result = str.replace(regex, ''); console.

如果有一个参数的值为
Window:String

const str = `fnct1(param: Int, Window: String): String func2(Window: String): String function3(param: String): String`;
const regex = /[^\s(]+\(Window:\s*String\): [^(\s]+\s*/gm;
const result = str.replace(regex, '');
console.log(result);
这对我来说很有效,并返回
fnct1(param:Int,Window:String):String函数3(param:String):String
我在regex中有硬代码
Window:String
,现在我想将其设置为泛型,因为类型可以是任何类型,并且执行与
Window:String
相同的操作

可能是

const str = `fnct1(param: Int, Window: String): String func2(Window: Int): String function3(param: String): String`;
const str = `fnct1(param: Int, Window: String): String func2(Window: String): String function3(param: String): String`;

有人知道怎么做吗?

您希望替换
窗口:
和0+空格后的任何一个或多个单词

你可以用

/[^\s(]+\(Window:\s*\w+\):\s*[^(\s]+\s*/g

var str=“fnct1(参数:Int,窗口:字符串):字符串函数2(窗口:字符串):字符串函数3(参数:字符串):字符串”;
var regex=/[^\s(+]+\(窗口:\s*\w+\):\s*[^(+\s]+\s*/g;
var result=str.replace(正则表达式“”);

console.log(result);
\w+
替换
String
。谢谢@WiktorStribiżew你能回答吗?我可以接受吗