为什么我的表达式不能处理多行?

Why doesn't my expression handle multiline?

输入

下面这段代码是c++中对话框的资源声明

    LTEXT           "Width",IDC_WIDTH_TEXT,203,74,22,10
    EDITTEXT        IDC_WIDTH_IN,244,73,57,12,ES_AUTOHSCROLL | WS_GROUP
    CONTROL         "Manually scale instances and paper",IDC_RAD_PSCALE_KEYIN,
    "Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,15,89,132,10
    CONTROL         "Keep drawing instance scale 1.0",IDC_RAD_PSCALE_AUTO,
    "Button",BS_AUTORADIOBUTTON,15,104,123,10
    CONTROL         "Keep drawing paper scale 1.0",IDC_RAD_ISCALE_AUTO,
    "Button",BS_AUTORADIOBUTTON,15,119,118,10

期望的输出

我想使用 Visual Studio 2010 Find/Replace 对话框来处理该信息。

我想从该声明中提取所有 ID 并有一个清除列表,因此使用该输入我想获得以下输出:

IDC_WIDTH_TEXT
IDC_WIDTH_IN
IDC_RAD_PSCALE_KEYIN
IDC_RAD_PSCALE_AUTO
IDC_RAD_ISCALE_AUTO

1°尝试

如果我使用 .*{IDC:i*}.* 那么我可以获得所有这些 ID,但我不会从中获取多行部分,如果我将 </code> 放在替换字段中,这就是输出:</p> <pre><code>IDC_WIDTH_TEXT IDC_WIDTH_IN IDC_RAD_PSCALE_KEYIN "Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,15,89,132,10 IDC_RAD_PSCALE_AUTO "Button",BS_AUTORADIOBUTTON,15,104,123,10 IDC_RAD_ISCALE_AUTO "Button",BS_AUTORADIOBUTTON,15,119,118,10

2°尝试

如果我改用 .*{IDC:i*}.*\n.*~({IDC:i*}),我会得到以下缺少 IDC_WIDTH_IN

的输出
IDC_WIDTH_TEXT
IDC_RAD_PSCALE_KEYIN
IDC_RAD_PSCALE_AUTO
IDC_RAD_ISCALE_AUTO

如何才能正确获得我想要的输出?

没有 language/program-specific dotall 修饰符,点通常匹配除换行符之外的所有内容。

试试这个 (demo)。请注意,我的演示中的替换将 \n 附加到末尾,否则它也会处理换行符并将所有内容放在一行中。

^.*?(IDC\w*)[\s\S]*?(?:$|(,\n.*$))(\n|$)

解释:

 ^                  # Anchors to the beginning to the string.
 .*?                # . denotes any single character, except for newline
                      # * repeats zero or more times
                      # ? as few times as possible
 (                  # Opens CG1
     IDC            # Literal IDC
     \w*            # Token: \w (a-z, A-Z, 0-9, _)
                      # * repeats zero or more times
 )                  # Closes CG1
 [\s\S]*?           # Character class (any of the characters within)
                      # A character class and negated character class, common expression meaning any character.
 (?:                # Opens NCG
     $              # Anchors to the end to the string.
 |                  # Alternation (NCG)
     (              # Opens CG2
         ,          # Literal ,
         \n         # Token: \n (newline)
         .*         # . denotes any single character, except for newline
         $          # Anchors to the end to the string.
     )              # Closes CG2
 )                  # Closes NCG
 (                  # Opens CG3
     \n             # Token: \n (newline)
 |                  # Alternation (CG3)
     $              # Anchors to the end to the string.
 )                  # Closes CG3