想象一下这个字符串:
if(editorPart instanceof ITextEditor){
ITextEditor editor = (ITextEditor)editorPart;
selection = (ITextSelection) editor.getSelectionProvider().getSelection();
}else if( editorPart instanceof MultiPageEditorPart){
//this would be the case for the XML editor
selection = (ITextSelection) editorPart.getEditorSite().getSelectionProvider().getSelection();
}
Run Code Online (Sandbox Code Playgroud)
我可以直观地看到,这些行中的"常见"开头是两个制表符.是否有一个正则表达式将替换 - 只在每行的开头(包括第一行和最后一行),这个常见的开头,这样在正则表达式之后我最终会得到相同的字符串,只是基本上没有缩进?
在这种情况下,我不能简单地搜索"两个标签",因为文本中的其他地方可能有两个标签但不在行的开头.
我用不同的方法实现了这个功能,但认为它是一个有趣的正则表达式挑战,如果它可能的话
在^正则表达式符号一行的开头匹配.所以:
/^\t\t//g
Run Code Online (Sandbox Code Playgroud)
将在行的开头删除两个制表符.