开发者

Get content from bracket

With preg_match how can I get the string between the bracket

E开发者_如何学Goxample: sdsdds (sdsd) sdsdsd

And I want the

sdsd


preg_match('/\(([^\)]*)\)/', 'sdsdds (sdsd) sdsdsd', $matches);
echo $matches[1]; // sdsd

Matches characters within parentheses, including blank values. If you want to match multiple instances, you can use preg_match_all.


preg_match('/\((.*?)\)/', $text, $a);
echo $a[1];


The simplest:

#\(([^\)]+)\)#

It's not very readable, because all the ( and ) must be escaped with \.

The # are delimiters.

Using preg_match:

$str = 'sdsdds (sdsd) sdsdsd';
$iMatches = preg_match('#\(([^\)]+)\)#', $str, $aMatches);
echo $aMatches[1]; // 'sdsd'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜