Grabbing the href attribute of an A element

前端 未结 10 2375
悲&欢浪女
悲&欢浪女 2020-11-21 05:06

Trying to find the links on a page.

my regex is:

/]*href=(\\\"\\\'??)([^\\\"\\\' >]*?)[^>]*>(.*)<\\/a>/
10条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-21 05:52

    Quick test: ]*href=(\"\'??)([^\1]+)(?:\1)>(.*)<\/a> seems to do the trick, with the 1st match being " or ', the second the 'href' value 'that', and the third the 'what?'.

    The reason I left the first match of "/' in there is that you can use it to backreference it later for the closing "/' so it's the same.

    See live example on: http://www.rubular.com/r/jsKyK2b6do

提交回复
热议问题