![](/img/trans.png)
[英]How to check whether a string with more words contains a substring with more words in JavaScript?
[英]How to test whether string contains multiple defined words in order?
我有一個字符串,需要測試是否按順序包含多個定義的單詞。
例如,預定義的單詞是: ["one", "two", "three"]
因此,帶有"one two three"
的字符串應返回true,但帶有"three two one"
的字符串應返回false。
我當前的正則表達式如下: new RegExp('\\\\bone\\\\b\\\\two\\\\b\\\\three\\\\b')
不幸的是,這只是檢查單詞是否存在,而不關心它們的順序是否正確。
您可以只使用此正則表達式
var arr = ["one", "two", "three"];
var regex = new RegExp(arr.join(".*"));
arr.join(".*")
將使正則表達式為/one.*two.*three/
您可以使用以下正則表達式。
var re = /one.*two.*three/
例:
re.test('one two three'); // true
re.test('three two one'); // false
先生,請檢查這些是什么錯誤。 我不知道這個。 代碼不會彈出。
這是彈出的點擊。
<li><a href="#"><i class="icon-envelope icon-2x" onClick="click();"></i></a></li>
這是JavaScript代碼。
<script type="text/javascript" src="//www.klaviyo.com/media/js/public/klaviyo_subscribe.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('icon-envelope icon-2x').on('click',function(){
KlaviyoSubscribe.attachModalSignUp({
list: 'g9cZtX',
delay_seconds: 0.5,
content: {
clazz: ' klaviyo_modal_g9cZtX',
header: "Interested in our Newsletter?",
subheader: "Stay in the know with news and promotions.",
button: "Subscribe",
success: "Thanks! Check your email for a confirmation.",
styles: '.klaviyo_modal.klaviyo_modal_g9cZtX { font-family: "Helvetica Neue", Arial}.klaviyo_modal.klaviyo_modal_g9cZtX .klaviyo_header { color:#222;}.klaviyo_modal.klaviyo_modal_g9cZtX .klaviyo_subheader { color:#222;}.klaviyo_modal.klaviyo_modal_g9cZtX .klaviyo_submit_button,.klaviyo_modal.klaviyo_modal_g9cZtX .klaviyo_submit_button span { background-color:#07234F; background-image: none; border-radius: 2px;}.klaviyo_modal.klaviyo_modal_g9cZtX .klaviyo_submit_button:hover,.klaviyo_modal.klaviyo_modal_g9cZtX .klaviyo_submit_button span:hover { background-color:#2A4D85; background-image: none; }.klaviyo_modal.klaviyo_modal_g9cZtX .klaviyo_inner,.klaviyo_modal.klaviyo_modal_g9cZtX .klaviyo_fieldset .klaviyo_field_group input[type=text],.klaviyo_modal.klaviyo_modal_g9cZtX .klaviyo_fieldset .klaviyo_field_group input[type=email] { border-radius: 2px;}'
}
});
});
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.