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 關注
- 181 瀏覽
添加回答
舉報