ste*_*eve 7 regex quotes ignore escaping
披露:我已经在这里多次阅读了这个答案,我知道比使用正则表达式解析HTML更好.这个问题只是为了扩展我的正则表达式的知识.
说我有这个字符串:
some text <tag link="fo>o"> other text
我想匹配整个标签,但如果我使用<[^>]+>它只匹配<tag link="fo>.
如何确保>可以忽略引号内部.
我可以用一个while循环来编写一个解析器来执行此操作,但我想知道如何使用regex.
Vas*_*kis 12
<[^>]*?(?:(?:('|")[^'"]*?\1)[^>]*?)*>
我知道这个正则表达式看起来很头疼,所以这是我的解释:
<                      # Open HTML tags
    [^>]*?             # Lazy Negated character class for closing HTML tag
    (?:                # Open Outside Non-Capture group
        (?:            # Open Inside Non-Capture group
            ('|")      # Capture group for quotes, backreference group 1
            [^'"]*?    # Lazy Negated character class for quotes
            \1         # Backreference 1
        )              # Close Inside Non-Capture group
        [^>]*?         # Lazy Negated character class for closing HTML tag
    )*                 # Close Outside Non-Capture group
>                      # Close HTML tags
| 归档时间: | 
 | 
| 查看次数: | 5309 次 | 
| 最近记录: |