2012-11-22 38 views

回答

3

要匹配行開始:

> 'abcdef'.match(/^/) 
[ '', index: 0, input: 'abcdef' ] 

要匹配字面^,逃吧:

> 'abcdef'.match(/\^/) 
null 

要匹配字面^一類的人物裏面,把它放在任何位置,除了第一:

> 'abcdef'.match(/[xyz^]/) 
null 
> 'abcdef'.match(/[def^]/) 
[ 'd', index: 3, input: 'abcdef' ] 
0

如果你只是想檢查字符串是否包含脫字符號碼

/\^/.test("abcdef"); // => false 
/\^/.test("^abcdef"); // => true 
/[^\^]/.test("aslkfdjfs"); // =>true as caret does not exist in string 
1

使用.search(/\^/)。反斜槓'\'將刪除'^'的功能。這樣您可以限制。