フィルターのクリア

Find string with options (*)

13 ビュー (過去 30 日間)
Horace Lai
Horace Lai 2013 年 5 月 30 日
Hi,
I have a cell of strings that I want to see if any of them match a certain string pattern. The string pattern can be something like 'Object(1)=' or Object(123)='. So basically 'Object(*)=' where the asterisk represents a number. Is there a function in Matlab that has a feature that can search strings like that?
Horace

採用された回答

José-Luis
José-Luis 2013 年 5 月 30 日
編集済み: José-Luis 2013 年 5 月 30 日
expr = 'Object\([0-9]*\)='; %Regular expression
bla = 'asad ca Object(0)= asdas Object(k)=asdObject(1999)='; %string to search
your_idx = regexp(bla,expr); %Returns starting index of matches
Note that you can also get the index of the ending of the matches, the matched strings themselves, etc... For more details please look at:
doc regexp
  1 件のコメント
Horace Lai
Horace Lai 2013 年 5 月 30 日
Thanks. Just what I was looking for

サインインしてコメントする。

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 30 日
編集済み: Azzi Abdelmalek 2013 年 5 月 30 日
s='123 sdd5 Object(1)= 25 333sss'
idx=strfind(s,'Object(1)=')
%or
k=123
pattern=sprintf('Object(%d)=',k)
s='123 sdd5 Object(123)= 25 333sss'
idx=strfind(s,pattern)
  2 件のコメント
Horace Lai
Horace Lai 2013 年 5 月 30 日
Hi, thanks for the response. But it wasn't really what I was looking for. I am looking for a solution where you do not know the number before hand. In your first example you knew the number was 1 and in the second you knew hte number was 123.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 30 日
idx=regexp(s,'Object\(\d*\)=')

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by