gpt4 book ai didi

javascript - 如何将 javascript var 与文本连接起来?

转载 作者:行者123 更新时间:2023-11-28 05:15:38 25 4
gpt4 key购买 nike

如何将 javascript var xx/\\b/ 连接起来?

https://jsfiddle.net/6r4o5278/6/

<div onclick="check()">CLICK HERE</div>

<script>
function check() {
var str = "abcdefg";
var xx = "abc";
if (/\+xx+\b/.test(str))
{
alert("found");
} else
{
alert("not found");
}
}
</script>

最佳答案

“将 javascript var xx 与/\和\b/连接”是什么意思?另请参阅:

http://www.w3schools.com/jsref/jsref_regexp_test.asp

// The string:
var str = "Hello world!";

// Look for "Hello"
var patt = /Hello/g;
var result = patt.test(str);

// Look for "W3Schools"
patt2 = /W3Schools/g;
result2 = patt2.test(str);

关于javascript - 如何将 javascript var 与文本连接起来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40998205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com