Contents Previous Next Subchapters Current Chapters-> align atod atoi char2dbl ntoa num2str str2num strreplace strclip clipstr low2up up2low dquote file2str pack unpack char2id reprow str2strdir sort sort3 psort psort3 mlmode_sort reverse flipud fliplr rot90 nonzeros find find2 find3 dec2hex hex2dec findstr whichrow Parent Chapters-> Omatrix6 stringssort findstr Search Tools-> contents reference index search

Searching Strings and Matrices using Regular Expressions
 Syntax `findstr(`x`, `pattern```) [R, C, M] = findstr(```x`, `pattern`)` See Also lower , find2 , strreplace , ntoa , align

Description
Finds strings in the character matrix x that match the regular expression pattern. If called with one return value, `findstr` returns all rows of x that contain at least one match for pattern. If called with three return values, `findstr` returns the row and column indices in x where matches were found, and the length of each match. The values, R, C and M are integer column vectors with row dimension equal to the number of matches found in x. ``` ```O-Matrix uses Perl-compatible Regular Expressions for the argument pattern. See http://search.cpan.org/dist/perl/pod/perlre.pod for more details about Perl-compatible regular expressions.

Examples
If you enter, ```      findstr({"hip",  "hipe",  "hills",  "hope",  "Hippy"},  "[hH].p+") ``` O-Matrix will respond ```     hip       hipe     hope      Hippy ``` If you continue the example by entering ```      S = {"hip",  "hipe",  "hills",  "hope",  "Hippy"}      [R,C,M]=findstr(S,  "[hH].p+")      print [R, C, M] ``` O-Matrix will return, ```     {     [ 1 , 1 , 3 ]     [ 2 , 1 , 3 ]     [ 4 , 1 , 3 ]     [ 5 , 1 , 4 ]     } ``` where R contains the row indices of each match, C contains the column indices of each match, and M contains the length of each match. If you continue by entering the following, ```     for i = 1 to rowdim(R) begin         print S.blk( R(i), C(i), 1, M(i) )     end  ``` O-Matrix will print each of the matched strings, ```     hip      hip      hop      Hipp  ```