regex - Why is my regexp matching multiple times? -


i have following line want capture several strings via regular expression:

l = '15                 1180       62444    e0e0                   049c     f3ec      104'; 

i augmenting following regexp operate on line:

d = regexpi(l, '([0-9a-f]+)\s?', 'tokens'); 

when executing line, length(d) == 7. shouldn't regexp match first occurrence, i.e., length(d) == 1 , d{1} == '15'?

for it's worth, used same regexp in perl , found matches first instance of pattern (which expected):

my $l = ... #defined above $l =~ m/([0-9a-f]+)\s?/i;  if (! defined($2)){ # $2, $3, ..., $n defined n matches     print "didn't match twice!\n"; # prints when execute script } 

as stated using regexpi...

start = regexpi(str,expr) returns row vector, start, containing indices of substrings in str match regular expression string, expr, regardless of case.

when either str or expr cell array of strings, regexpi returns m-by-n cell array of row vectors of indices, m the number of strings in str , n number of regular expression patterns in expr.

[start,finish] = regexpi(str,expr) returns additional row vector finish, contains indices of last character of corresponding substrings in start.

[start,finish,tokens] = regexpi(str,expr) returns 1-by-n cell array, tokens, of beginining , ending indices of tokens within corresponding substrings in start , finish. tokens denoted parentheses in expression, expr.

[...] = regexpi(str,expr,'once') finds first match. (by default, regexp returns matches.) if no matches found, return values empty.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -