2017-02-17 89 views

回答

4

您需要使用創建一個Regular Expression和使用.test()方法。

var randomString = 'justanother.string'; 
 
var a = /^just\./.test(randomString) 
 
console.log(a);

1

答案很簡單,你沒有propertly創建正則表達式。
'this is not regex'
/this is regex/ new RexExp('this is also regex')

var randomString = 'justanother.string'; 
 
\t 
 
var a = randomString.match(/^just\./); 
 

 
console.log(a); 
 

 
// I sugest dooing something like this 
 
const startsWithJust = (string) => /^just\./.test(string)

1

var randomString = 'justanother.string'; 
 
var another = 'just.....................'; 
 
console.log( randomString.match('^(just[.]).*')); 
 
console.log( another.match('^just[.].*'));

+0

noo這會匹配'just.',而且'just'和'只是............................... .. ........................' –

0

如果你想保持你的線需要相同的只有一個變化。

var a = randomString.match('^just\\.'); 

您需要轉義第一個反斜槓。

相關問題