繁体   English   中英

php中用于匹配'['和']'之间的任何内容的preg_match解决方案是什么?

[英]what is the preg_match solution in php for matching anything between '[' and ']'?

我有很多像这样的字符串

[anything]

这个词在哪里

anything == any kind of characters, such as ~!@#$%^&*()

用于匹配PHP中此类字符串的preg_match()代码将是什么?

这应该可以满足您的需求:

<?php
$matches = array();
preg_match_all('/\[(.+?)\]/s', $string, $matches);
foreach ($matches[1] as $match) {
    // Do stuff here.
}

在您的字符串中找到方括号之间的文本的所有时间都会循环遍历。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM