cle*_*tus 74
您可以在Javascript中使用正则表达式来进行字符串的模式匹配.
例如:
var s = "hello world!";
if (s.match(/hello.*/)) {
// do something
}
Run Code Online (Sandbox Code Playgroud)
该match()测试是很像WHERE s LIKE 'hello%'的SQL.
Noo*_*ilk 27
没有.
您想使用:.indexOf("foo")然后检查索引.如果它> = 0,则它包含该字符串.
Ash*_*Ash 19
使用字符串对象匹配方法:
// Match a string that ends with abc, similar to LIKE '%abc'
if (theString.match(/^.*abc$/))
{
/*Match found */
}
// Match a string that starts with abc, similar to LIKE 'abc%'
if (theString.match(/^abc.*$/))
{
/*Match found */
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
159728 次 |
| 最近记录: |