在第一个open brace regex Notepad ++中找到内容

时间:2017-05-13 01:13:16

标签: regex notepad++

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

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被添加到给定内容的两侧) 非常感谢你!

1 个答案:

答案 0 :(得分:0)

您可以使用这样的简单正则表达式:{\\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.}