php - 正则表达式匹配特定标签和介于两者之间的任何字符
问题描述
我正在尝试使用正则表达式来匹配特定标签和特定标签之间的任何字符/内容。请注意,标签之间的内容是动态的,因此可以更改。
我想匹配[vc_row el_class="hero-cta和[/vc_row]之间的所有内容
我尝试使用以下正则表达式进行此操作,但问题是它匹配所有[vc_row]标签,因为我希望能够仅匹配[vc_row el_class="hero-cta标签、内部内容和结束[/vc_row]标签
我尝试的正则表达式(不正确,因为它匹配所有 [vc_row] 标签)
\[vc_row el_class=[^\]].*\"\]([\s\S]*)\[\/vc_row\]
我怎样才能适应这个正则表达式?
内容
<!--match-->
[vc_row el_class="hero-cta image_flush_bottom" css=".vc_custom_1382221210419{background-color: #511068c !important;}"][vc_column][vc_row_inner el_class="container-row-margin-btm-override"][vc_column_inner width="2/3"][vc_column_text]
<h2><em><strong>Download Guide</strong></em></h2>
[/vc_column_text][/vc_column_inner][vc_column_inner width="1/3"][vc_single_image image="12346" img_size="full" alignment="center" onclick="custom_link" link="https://www.website.com/test-page"]
[/vc_column_inner][/vc_row_inner][/vc_column][/vc_row]
<!--//match-->
<!--ignore-->
[vc_row][vc_column][breadcrumb][/vc_column][/vc_row]
<!--//ignore-->
解决方案
在 WordPress 中具有get_shortcode_regex
查找所有简码的功能。
echo get_shortcode_regex( [ 'vc_row' ] );
此常规可以帮助您找到所有 vc_row 短代码。您可以根据您的目的重新格式化此常规。
推荐阅读
- node.js - GraphQL 订阅 - subscriptionsClient.subscribe 不是函数
- arrays - 算法/数据结构名称请求:固定大小的数组,覆盖时步幅增加
- google-cloud-platform - 项目之间的 GKE 连接
- c# - C#中的反向Fisher-Yates Shuffle
- autodesk-forge - 使用 Forge 获取 Revit 版本的 BIM 360 文件
- shapes - Mxgraph 检查添加了哪个形状
- go - 冲突的匹配嵌入式接口方法是功能、错误还是其他?
- c++ - 如何删除已经输入的书籍,如何让书名、语言、名字在上面加空格不出错?
- java - 如何在另一个 HBase 过滤器之上应用一个 HBase 行过滤器?
- tensorflow - 如何在张量流中复制列?