PHP preg_match正则表达式

  • 行定位符 ^表示开始 $表示结束

preg_match(模式,待搜索的字符串,$matches) 其中matches为可选参数,一旦匹配上,可以返回匹配结果

举个例子:

$pattern = '/#\S+/';  \S表示任何非空白字符(由于例子中使用的是中文所以这里不能使用\w)

$mystr = "(r'/loadcolspage',loadcolspage),#列加工器";

preg_match($pattern,$mystr,$matches);

var_dump($matches);

打印结果:
array(1) {
  [0]=>
  string(13) "#列加工器"
}

猜你喜欢

转载自www.cnblogs.com/saintdingspage/p/10929880.html