【问题标题】:Find the content in the first open brace regex Notepad++在第一个大括号正则表达式 Notepad++ 中查找内容
【发布时间】:2017-05-13 10:19:19
【问题描述】:

假设我们有以下三行内容:

cnt1 {\abc asd{} sd {{d}} def.}
cnt2 {\abc hgj{} sd {sd} {{d}} def.}
cnt3 {\def asd{} sd {{d}} def.}

如我们所见,这里有很多左大括号和右大括号,我可以过滤第一行和第二行的内容吗,它有相似的内容“{\abc”和每一行的开头,但每个都有不同的大括号数和里面的内容。我只是想这个问题是如何检测其起始内容为“\ abc”的每一行的第一个左大括号(父大括号)的内容。

假设内容 "{\abc asd{} sd {{d}} def.}" = $1,并且 "{\abc hgj{} sd {sd} {{d}} def.}" = $2 .我怎样才能得到想要的结果

cnt1 x$1y
cnt2 g$2h
cnt3 {\def asd{} sd {{d}} def.}

(x,y 和 g,h 添加到给定内容的两侧) 非常感谢!

【问题讨论】:

  • 请看看我的问题...

标签: regex notepad++


【解决方案1】:

您可以像这样使用简单的正则表达式:{\\abc.*}

    String str = 
            "cnt1 {\\abc asd{} sd {{d}} def.}\n" +
            "cnt2 {\\abc hgj{} sd {sd} {{d}} def.}\n" +

            "cnt3 {\\def asd{} sd {{d}} def.}\n";
    Pattern pat=Pattern.compile("\\{\\\\abc.*}");
    Matcher matcher=pat.matcher(str);
    while(matcher.find()){
        System.out.println(matcher.group(0));
    }

显然{必须被转义

输出:

{\abc asd{} sd {{d}} def.}
{\abc hgj{} sd {sd} {{d}} def.}

【讨论】:

  • 我想在记事本++中这样做
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-12
相关资源
最近更新 更多