Regex to Parse Hyperlinks and Descriptions

前端 未结 6 1839
长情又很酷
长情又很酷 2020-12-11 07:20

C#: What is a good Regex to parse hyperlinks and their description?

Please consider case insensitivity, white-space and use of single quotes (instead of double quote

6条回答
  •  执笔经年
    2020-12-11 08:21

    As long as there are no nested tags (and no line breaks), the following variant works well:

    (.*?)
    

    As soon as nested tags come into play, regular expressions are unfit for parsing. However, you can still use them by applying more advanced features of modern interpreters (depending on your regex machine). E.g. .NET regular expressions use a stack; I found this:

    (?:.*?)[""'].*?>)(?(?>(?)|(?<-DEPTH>)|.)+)(?(DEPTH)(?!))(?:) 
    

    Source: http://weblogs.asp.net/scottcate/archive/2004/12/13/281955.aspx

提交回复
热议问题