我已经尝试在正则表达式下面从中捕获一些字符串:
"CallbackFnCreate_[\W]{4}(.*?[^\w-])
Required Output should be : /TestResult_20190604-120620 (Capture
TestResult_20190604-120620 and append "/" in the beginning)
我的第 1 组输出是:TestResult_20190604-120620"
1|#||4|3952|updatePanel|WorkflowFileExplorer_ajaxPanel|<div `id="WorkflowFileExplorer_pbContainer" style="width:0px;height:0px;overflow:hidden;position:relative;"><input type="button" name="WorkflowFileExplorer$pb" value="pb" onclick="javascript:__doPostBack('WorkflowFileExplorer$pb','')" id="WorkflowFileExplorer_pb" tabindex="-1" /><input name="WorkflowFileExplorer$postbackArgument" type="hidden" id="WorkflowFileExplorer_postbackArgument" value="CallbackFnCreate_/***TestResult_20190604-120620" /></div><div id="WorkflowFileExplorer_tree" class="RadTreeView RadTreeView_Default">`
最佳答案
我的猜测是我们希望简单地进行替换并稍微修改原始表达式:
.+("CallbackFnCreate_\/\*\*\*(.+?)").+
我们想要的输出在这个捕获组中:
(.+?)
测试
const regex = /.+("CallbackFnCreate_\/\*\*\*(.+?)").+/gm;
const str = `1|#||4|3952|updatePanel|WorkflowFileExplorer_ajaxPanel|<div \`id="WorkflowFileExplorer_pbContainer" style="width:0px;height:0px;overflow:hidden;position:relative;"><input type="button" name="WorkflowFileExplorer\$pb" value="pb" onclick="javascript:__doPostBack('WorkflowFileExplorer\$pb','')" id="WorkflowFileExplorer_pb" tabindex="-1" /><input name="WorkflowFileExplorer\$postbackArgument" type="hidden" id="WorkflowFileExplorer_postbackArgument" value="CallbackFnCreate_/***TestResult_20190604-120620" /></div><div id="WorkflowFileExplorer_tree" class="RadTreeView RadTreeView_Default">\`
`;
const subst = `\/$2`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
关于javascript - 正则表达式附加字符并删除结束双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56451833/