Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.0.0 - 日本語

Change language to:
English - Français - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Scilabヘルプ >> Strings > grep

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に正規表現文字列を指定できます. この場合, grepneedle を正規表現として使用し,正規表現の規則に基づいて 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')

参照

  • strindex — 他の文字列の中で指定した文字列の位置を探す.
  • regexp — 正規表現文字列に一致する部分文字列を探す
Report an issue
<< evstr Strings isalphanum >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 14 15:10:32 CET 2017