Contents Previous Next Subchapters

Searching Strings and Matrices using Regular Expressions
Syntax findstr(xpattern)
[R, C, M] = findstr(
xpattern)
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