regexp匹配正则表达式。[startIndex,endIndex]= regexp(str,expression),其中str是输入的字符串expression是正则表达式,返回值为子串的开始和结束下标。如果expression是普通的字符串,就变成了查找子串的下标;如果expression是正则表达式,就查找满足正则表达式的子串的下标。
举例:
>> [startIndex,endIndex]= regexp('hello world','or')
startIndex =
8
endIndex =
9
>> [startIndex,endIndex]= regexp('hello world',' ')
startIndex =
6
endIndex =
6
>> str = 'bat cat can car coat court CUT ct CAT-scan';
expression = 'c[aeiou]+t';
startIndex = regexp(str,expression)
startIndex =
5 17