find matches of a string in a vector of strings
[row, which] = grep(haystack, needle ) [row, which] = grep(haystack, needle, "regexp" )
a row vector of character strings.
a character string or a row vector of character strings. The string(s) to search in
a vector of indices: row where a match has been found or an empty matrix if no match found.
a vector of indices: index of
needlestring found or an empty matrix if no match found.
- "regexp" | "r" flag
single character: Then
needleelements are used as regular expressions.
For each entry of
searches if at least a string in
needle which matches a
haystack entries index where at least a
match has been found are returned in the
argument. The optional
which output argument gives the
index of first string of
When using the third parameter
needle is expected to be a regular expression string.
In this case,
grep uses the
needle as a regular expression and compares it
haystack according to the regular expressions
rules. See the regexp function for details about
In the following example, we search one or two strings in a text,
which is stored in the
txt=['find matches of a string in a vector of strings' 'search position of a character string in another string' 'Compare Strings']; grep(txt,'strings') grep(txt,['strings' 'Strings']) [r,w]=grep(txt,['strings' 'Strings'])
In the following example, we perform regexp searches.
str = ["hat";"cat";"hhat";"chat";"hcat";"ccchat";"at";"dog"] grep(str,'/[hc]+at/','r') grep(str,'/[hc]?at/','r') grep(str,'/cat|dog/','r')
- strindex — search position of a character string in another string
- regexp — find a substring that matches the regular expression string
- find — gives the indices of %T or non-zero elements
- vectorfind — locates occurences of a (wildcarded) vector in a matrix or hypermatrix
|Report an issue|
|<< evstr||Strings||isalphanum >>|