正则表达式
问题描述:
我打电话WordPress的API,并得到一个帖子的内容,但它在那里有标签和我试图将它们过滤掉,以获得实际的HTML,这里有一个例子:正则表达式
<p>[vc_row css=”.vc_custom_1499904320526{margin-top: 0px
!important;border-top-width: 0px !important;padding-top: 5px
!important;}”][vc_column][vc_custom_heading
source=”post_title”
font_container=”tag:h2|text_align:center”
use_theme_fonts=”yes”][vc_column_text]<strong>START
HERE</strong></p>\n<p>Release Date:<br />\nVersion:</p>\n<p>I am text
block. Click edit button to change this text. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper
mattis, pulvinar dapibus leo.</p>\n<p>[/vc_column_text][/vc_column]
[/vc_row][vc_row][vc_column width=”1/4″
offset=”vc_hidden-lg vc_hidden-md vc_hidden-sm vc_hidden-xs”]
<style type=\"text/css\" scoped=\"scoped\">
我尝试使用正则表达式来摆脱那些方括号[
]
和这里就是我写之间的任何东西:/\[[^]]*\]/g
。
var exp = /\[[^]]*\]/g;
console.info('WP resp',latestReleaseNotes.content.rendered.search(exp));
它安慰了-1和不匹配:
WP resp -1
我在做什么 这种模式,当我在regex website运行它,但是当我这样做匹配错误?
您确定要使用正则表达式解析HTML标签? –
@cᴏʟᴅsᴘᴇᴇᴅ我应该使用什么?我所瞄准的最终结果只是HTML而没有wordpress标签 –
在regex101中使用正确的语言设置。看看[你的正则表达式](https://regex101.com/r/iCIvjy/1)与[正确的正则表达式](https://regex101.com/r/iCIvjy/2) –