1 回答

TA贡献1828条经验 获得超4个赞
如果你只想匹配句子,你可以使用第一个匹配,然后是除or[vc_column_text
之外的任何字符,然后匹配结束[
]
]
然后匹配 0+ 次出现的空白字符并捕获 1 次或多次出现的任何字符,但组 1 中的空白除外。
\[vc_column_text[^][]*\]\s*(.+?)\[/vc_column_text]
解释
\[vc_column_text
匹配[vc_column_text
[^][]*\]
匹配[
,然后出现 0+ 次除[
or]
和匹配之外的任何字符]
\s*
匹配 0+ 个空格字符(.+?)
捕获组 1,匹配任何字符 1+ 次非贪婪\[/vc_column_text]
匹配[/vc_column_text]
示例代码
$string = '[vc_row][vc_column][/vc_column][/vc_row][vc_row][vc_column width="1/2"][vc_column_text css=".vc_custom_1576642149231{margin-bottom: 0px !important;}"]This is the string I want to fetch[/vc_column_text][/vc_column][/vc_row]';
preg_match_all("~\[vc_column_text[^][]*\]\s*(.+?)\[/vc_column_text]~", $string, $matches);
print_r($matches[1]);
输出
Array
(
[0] => This is the string I want to fetch
)
- 1 回答
- 0 关注
- 180 浏览
添加回答
举报