const regex = /(.*)\/\/(.*)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(.*)\\\/\\\/(.*)', 'gm')
const str = ` id: string;
avatar: string;
name: string; // 名称
brief: string; // 简介
type: string; // ip 形象类型 image:图片类型|figure2d:2d数字人
dubbingId: string; // 默认配音
percent: string; // 比例
previewUseVideo: {
// 预览使用视频
url: string; // 地址
};
coverUrl: string; // 封面url
videoUrl: string;
duration: number; // 时长(s)`;
const subst = ` /** $2 */ \n $1`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions