JavaScript/正则

来自康健生活

引言

indexOf

'康健在干嘛'.indexOf('康健') != -1
true

match

'康健在干嘛'.match(/康健/);
['康健', index: 0, input: '康健在干嘛', groups: undefined]
'康健在干嘛'.search('康健') != -1
true

test

'康健在干嘛'.test('康健') != -1
true

exec

RegExp(/康健/).exec('康健在干嘛');
['康健', index: 0, input: '康健在干嘛', groups: undefined]