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

PHP

$str="sd1231231@qq.com";
$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="sd1231231@qq.com"; 
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:="sd1231231@qq.com"
	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()
}

java

String strr = "%%%%%%%%804633234@qq.com$$$$$$$$$$$$$8888@qq.com&&&&&&&&";
        //定义爬取规则
        String regex1 = "[0-9a-zA-Z_]+@[0-9a-z]+\\.com";
        //编译正则表达式成为一个匹配的对象
        Pattern pattern1 = Pattern.compile(regex1);
        //通过匹配规则对象得到一个匹配数据内容的匹配器对象
        Matcher matcher1 = pattern1.matcher(strr);
        //通过匹配器去内容中爬取信息
        while (matcher1.find()) {
            System.out.println(matcher1.group());
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值