0

我正在使用 Visual Basic .NET,我正在尝试下载一串 HTML,我想替换它

    id="dynamicstring"

    id="replacement"

动态字符串可以是任何东西,这就是我无法替换它的原因。

4

1 回答 1

0

您可以将 id 属性的内容与此模式匹配:

(?<=<div\b(?>[^i]+|\Bi|i(?!d\s*=))*id\s*=\s*")[^"]+

细节:

(?<=                 # open a look behind assertion (it's just a check
                     # nothing is matched inside it)
    <div\b           # div tag
    (?>              # atomic group (all the content until the id attribute
        [^i]+        # all that is not a "i"
      |              # OR
        \Bi          # a "i" not preceded by a word boundary
      |              # OR
        i(?!d\s*=)   # a "i" (with an implicite word boundary) 
                     # not followed by "d="
    )*               # close the atomic group and repeat as necessary
    id\s*=\s*"       # the id attribute until the first double quote
)                    # close the lookbehind
[^"]+                # content of the id attribute
                     # (all that is not a double quote)
于 2013-08-18T19:10:42.383 回答