感谢编写 Nodejs 正则表达式的任何帮助。
首先搜索确切的单词“ChildBucketOne”和“ChildBucketTwo”,并在每次出现 ChildBucketOne 或/和 ChildBucketTwo 之前添加确切的单词 ParentBucket。
我正在尝试使用一个正则表达式。
输入1:webApplication.ChildBucketOne 输入2:webApplication.ChildBucketTwo
输出:webApplication.ParentBucket.ChildBucket.ChildBucketOne
webApplication.ParentBucket.ChildBucket.ChildBucketTwo
谢谢!
最佳答案
您可以简单地使用JavaScript的字符串替换功能
let input1 = 'webApplication.ChildBucketOne';
let input2 = 'webApplication.ChildBucketTwo';
function preprocess(input){
return input.replace('.ChildBucket', '.ParentBucket.ChildBucket.ChildBucket');
}
console.log(preprocess(input1));
console.log(preprocess(input2));
现场表演 - https://jsitor.com/IUb7cRtvf
关于javascript - 正则表达式在 Node 中现有单词之前添加一个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56616423/