post processing on google urls

后端 未结 2 1263
挽巷
挽巷 2021-01-28 17:32

I have grabbed some urls from Google search results using a regular expression. It has provided me the links in the format given below. Now, I just want the scheme and the host.

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-28 18:12

    Regex to match the above mentioned URL's which are preceded by /url?q= ,

    \/url\?q=\K.*?(?=\/&)
    

    DEMO

    OR

    www\.[^.]*\.(?:org|com)
    

    DEMO

    Your PHP code would be,

    
    

    Output:

    array(1) {
      [0]=>
      array(2) {
        [0]=>
        string(28) "http://www.fertile-focus.com"
        [1]=>
        string(24) "http://www.genetests.org"
      }
    }
    

提交回复
热议问题