php正则表达式 正则匹配网址是否带http:// https://
if(preg_match("/\x20*https?\:\/\/.*/i","",$m)){
echo "yes";
}else{
echo "no";
}
求PHP匹配指定字符开头,指定字符结尾。中间,任意字符,的正则怎么写。$pattern = "/^".$a.".*".$b."$/";
另外,你的程序有问题,我帮你改好了,你看看吧。
完整的PHP程序如下:
<?php
$str_arr = array("iameverysorry","快乐编程,快乐生活","php教程编程","1997年香港回归","英语学习abc","[www.php100.com]
");
function pipei($str_arr, $a, $b){
$pattern = "/^".$a.".*".$b."$/";//求。匹配指定字符开头,指定字符结尾。中间,任意字符,的正则怎么写。
foreach ($str_arr as $str){
preg_match_all($pattern, $str, $matches);
echo $matches[0][0];
}
}
pipei($str_arr,"p","程");
?>
运行结果:
php教程编程
php正则表达式不包含http://开头的连接preg_replace("/( 这样? ^CPU Load 上面的正则可以用来验证字符串是否是CPU Load开头 如果要从一个带有换行符的字符串中提取出CPU Load开头的行,用下面的正则 ^CPU Load.* 唉! $subject = "[0.0.0.123]"; $pattern = '/http:\/\/\:(.*?)/'; $b = preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3); function test($str){ if (preg_match("/^[\x81-\xfe][\x40-\xfe]?/",$str)) { return "首字母有中文"; } return "首字母没中文"; } echo test("中1231213");//首字母有中文 echo test("123中");//首字母没中文 1、首先,你这是一个json 为什么不解析json 来获取。 2、根据你的固定17位,如下 $str='[{"CID":"23SP2C5eXBC337e6e","name":"wil","sex":"m","year":2011}]'; $reg = '#"CID":"(.{17})"#'; preg_match_all($reg , $str , $matches); var_dump($matches); 不需要正则,以下代码就能实现: <?php $str = '[www.sina.com.cn] if(strpos($str, '?') !== false) { $str = substr($str, 0, strpos($str, '?')); $last_pos = strrpos($str, '.') + 1; // .号最后出现的位置 echo substr($str, $last_pos); } else { $last_pos = strrpos($str, '.') + 1; // .号最后出现的位置 echo substr($str, $last_pos); } \s 匹配任何空白字符,包括空格、制表符、换页符等等。等价于 [ \f\n\r\t\v]。 \S 匹配任何非空白字符。等价于 [^ \f\n\r\t\v]。 关于你上面的代码,我复制粘贴执行的结果是“匹配” 我是windows 8 火狐浏览器