regexp
- regexp(str, ex) returns the starting index of each match of regular expression patterns specified in second argument
- [sidx eidx] = regexp(str, ex) returns starting indexes in sidx and end indexes in eidx.
- [op1 op2] = regexp(str, ex, op1, op2) returns the outputs specified in op1, op2. They can be:
- 'match': matching text will be considered
- 'split': no-matching text will be considered
Examples
>> str = 'a1C b1c a33c A12C a1bisC a23C' [str:a1C b1c a33c A12C a1bisC a23C] >> ex = 'a[123]+C'% 'a' + a single character in the list + 'C'
[ex:a[123]+C] >> [sidx eidx] = regexp(str,ex) [sidx:1x2 double] [eidx:1x2 double] >> sidx#% starting indexes
1 26 >> eidx#% end indexes
3 29
>> str = {'ac Abc'; 'abbc abbbc'}
[str:2x1 cell]
>> ex = 'ab*c' % 'a' + 'b' zero or more times + 'c'
[ex:ab*c]
>> [sidx eidx] = regexp(str,ex)
[sidx:2x1 cell]
[eidx:2x1 cell]
>> sidx{1}#
1
>> sidx{2}#
1 6
>> eidx{1}#
2
>> eidx{2}#
4 10
>> str = 'split this string' [str:split this string] >> ex = '\s';% whitespace
[ex:\s] >> strsplit = regexp(str,ex,'split') [strsplit:1x3 cell] >> strsplit# [split][this][string]
>> str = 'cat bla hat bat' [str:cat bla hat bat] >> ex = '.at';% any character + 'at'
[ex:.at] >> [match, nomatch] = regexp(str,ex,'match', 'split') [match:1x3 cell] [nomatch:1x4 cell] >> match# [cat][hat][bat] >> nomatch# [][ bla ][ ][]