- Scilabヘルプ
 - Strings
 - ascii
 - asciimat
 - blanks
 - char
 - convstr
 - emptystr
 - eval
 - evstr
 - grep
 - isalphanum
 - isascii
 - isdigit
 - isletter
 - isnum
 - justify
 - length
 - part
 - prettyprint
 - regexp
 - sci2exp
 - strcat
 - strchr
 - strcmp
 - strcmpi
 - strcspn
 - strindex
 - string
 - strings
 - stripblanks
 - strncpy
 - strrchr
 - strrev
 - strsplit
 - strspn
 - strstr
 - strsubst
 - strtod
 - strtok
 - tokenpos
 - tokens
 
Please note that the recommended version of Scilab is 2026.0.0. This page might be outdated.
See the recommended documentation of this function
grep
文字列のベクトルの中で指定した文字列に一致するかどうかを調べる
呼び出し手順
row=grep(haystack,needle ) [row,which]=grep(haystack,needle ) row=grep(haystack,needle ,[flag]) [row,which]=grep(haystack,needle ,[flag])
引数
- haystack
 文字列の行ベクトル.
- needle
 文字列または文字列の行ベクトル.
haystackの中で文字列を探します.- row
 インデックスのベクトル: 一致するものが見つかった行, または一致するものが見つからなかった場合は空の行列.
- which
 インデックスのベクトル: 見つかったneedle文字列のインデックスまたは 一致するものがなかった場合は空の行列.
- flag
 文字 (正規表現の場合は
"r")
説明
haystackの各エントリについて,
            grepは少なくとも
            needleの中の一つの文字列が
            部分文字列に一致するかどうかを探します.
            最低でも一致するものが一つある
            haystackのエントリのインデックスが
            出力引数rowに返されます.
            オプションの出力引数whichは,
            needleの最初に見つかった文字列のインデックスを
            指定します.
3番目のパラメータにflag="r"
            を指定した場合,
            needleに正規表現文字列を指定できます.
            この場合, grepはneedle
            を正規表現として使用し,正規表現の規則に基づいて
            haystackとこの文字列を比較します.
            正規表現に関する詳細については関数regexp
            を参照ください.
例 #1
以下の例では,txt変数に保存されている
            テキスト中で,1つまたは2つの文字列を探します.
txt=['find matches of a string in a vector of strings' 'search position of a character string in an other string' 'Compare Strings']; grep(txt,'strings') grep(txt,['strings' 'Strings']) [r,w]=grep(txt,['strings' 'Strings'])
例 #2
以下の例では, 正規表現検索を行ないます.
str = ["hat";"cat";"hhat";"chat";"hcat";"ccchat";"at";"dog"] grep(str,'/[hc]+at/','r') grep(str,'/[hc]?at/','r') grep(str,'/cat|dog/','r')
| Report an issue | ||
| << evstr | Strings | isalphanum >> |