在两个html标签之间查找正则表达式[重复]
Posted
技术标签:
【中文标题】在两个html标签之间查找正则表达式[重复]【英文标题】:Find Regex between two html tag [duplicate] 【发布时间】:2020-11-04 10:09:19 【问题描述】:<form action="/facial-sas/#wpcf7-f158-p566-o1" method="post" class="wpcf7-form cf7-style" novalidate="novalidate">
<div style="display: none;">
<input type="hidden" name="_wpcf7" value="158">
<input type="hidden" name="_wpcf7_version" value="5.1.9">
<input type="hidden" name="_wpcf7_locale" value="en_US">
<input type="hidden" name="_wpcf7_unit_tag" value="wpcf7-f158-p566-o1">
<input type="hidden" name="_wpcf7_container_post" value="566">
</div>
<div class="row">
<div class="small-12 columns">
<label>Select Department</label> <span class="wpcf7-form-control-wrap menu-78"><select name="menu-78" class="wpcf7-form-control wpcf7-select wpcf7-validates-as-required" aria-required="true" aria-invalid="false"><option value="Stem Cell Treatments">Stem Cell Treatments</option><option value="Hair Restoration">Hair Restoration</option><option value="Face & Body">Face & Body</option><option value="Aesthetics">Aesthetics</option><option value="Vaginal Rejuvenation">Vaginal Rejuvenation</option></select></span>
</div>
<div class="small-12 columns">
<label>Your Name</label> <span class="wpcf7-form-control-wrap your-firstname"><input type="text" name="your-firstname" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required full" aria-required="true" aria-invalid="false"></span>
</div>
<div class="small-12 columns">
<label>Phone</label> <span class="wpcf7-form-control-wrap phone"><input type="text" name="phone" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required full" aria-required="true" aria-invalid="false"></span>
</div>
<div class="small-12 columns">
<label>E-mail</label> <span class="wpcf7-form-control-wrap email"><input type="text" name="email" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required full" aria-required="true" aria-invalid="false"></span>
</div>
</div>
<div class="row">
<div class="small-12 columns">
<div id="cf7sr-5efbe15251408" class="cf7sr-g-recaptcha" data-theme="light" data-type="image" data-size="normal" data-sitekey="6Lcfm80UAAAAAARwri_XthNlglRc51eYQiyfEAGL"></div><span class="wpcf7-form-control-wrap cf7sr-g-recaptcha-invalid"></span><br>
<input type="submit" value="MAKE AN APPOINTMENT" class="wpcf7-form-control wpcf7-submit btn full accent"><span id="wpcf7-5efbe1525136e" class="wpcf7-form-control-wrap honeypot-678-wrap"><label class="hp-message">Please leave this field empty.</label><input class="wpcf7-form-control wpcf7-text" type="text" name="honeypot-678" value="" size="40" tabindex="-1" autocomplete="nope"></span>
</div>
</div>
<div class="wpcf7-response-output wpcf7-display-none" aria-hidden="true"></div></form>
在上面的代码中,我想在这两个标签之间查找并替换第一个开始标签“
【参考方案1】:你可以使用这个模式/(?<=[<fo]rm).+(?<![>])/g
str='<form action="/facial-sas/#wpcf7-f158-p566-o1" method="post" class="wpcf7-form cf7-style" novalidate="novalidate">'
pattern=/(?<=[<fo]rm).+(?<![>])/g
console.log(str.match(pattern)[0])
【讨论】:
以上是关于在两个html标签之间查找正则表达式[重复]的主要内容,如果未能解决你的问题,请参考以下文章
用于python的正则表达式来捕获两个XML标签之间的所有内容[重复]
正则表达式 - 从 HTML 文件中查找各种字符串 [重复]