php python go 正则匹配 及发送post get请求 php curl

PHP

$str="[email protected]";
$pattern = '/^[0-9a-zA-Z_]+@[0-9a-z]+\.com/'; 

if(preg_match_all($pattern, $str, $matches)){
	print_r($matches);
}else{
	print_R("no");
	print_r($matches);
}


// public  function http_request( $url,$post = '', $timeout = 60){
// 	if( empty( $url ) ){
// 		return ;
// 	}
// 	$ch = curl_init();
// 	curl_setopt($ch, CURLOPT_URL, $url);
// 	curl_setopt($ch, CURLOPT_HEADER, 0);
// 	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// 	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// 	curl_setopt($ch, CURLOPT_ENCODING, '');
// 	curl_setopt($ch, CURLOPT_POST, 1);
// 	curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
// 	curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
// 	$result = curl_exec($ch);
// 	curl_close($ch);
// 	return $result;
// }

python

import re  
import requests

mail="[email protected]"; 
result=re.match(r'^[0-9a-zA-Z_]+@[0-9a-z]+\.com',mail)
if result:  
    print(result)  
else:  
    print(result) 


//url = "https://www.baidu.com"
//data = {"key":"value"}
//res = requests.post(url=url,data=data)
//print(res.text)

go


package main

import (

	"fmt"
	"regexp"
	"bytes"
	"io"
	"net/http"
	"time"
)


func main(){


	//url:=Get("https://www.baidu.com")
    str:="[email protected]"
	reg1 := regexp.MustCompile(`^[0-9a-zA-Z_]+@[0-9a-z]+\.com`)
	if reg1 == nil {
		fmt.Println("regexp err")
		return
	}
	//根据规则提取关键信息
	result1 := reg1.FindAllStringSubmatch(url, -1)
	fmt.Println("result1 = ", result1)


}


// 发送GET请求
// url:         请求地址
// response:    请求返回的内容
func Get(url string) string {

	// 超时时间:5秒
	client := &http.Client{Timeout: 5 * time.Second}
	resp, err := client.Get(url)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	var buffer [512]byte
	result := bytes.NewBuffer(nil)
	for {
		n, err := resp.Body.Read(buffer[0:])
		result.Write(buffer[0:n])
		if err != nil && err == io.EOF {
			break
		} else if err != nil {
			panic(err)
		}
	}

	return result.String()
}

猜你喜欢

转载自blog.csdn.net/zhang804633234/article/details/121122669