フィルターのクリア

stuck again with regular expression

1 回表示 (過去 30 日間)
Max Müller
Max Müller 2014 年 10 月 5 日
コメント済み: Azzi Abdelmalek 2014 年 10 月 5 日
Hey Guys, I want to get the Letter before the word CAMERA out of this String:
SHOT -31045 J CAMERA
I know i need to use regexp. I have create this code
regexp(str,'(SHOT)+\b+[0-9]+\b+(.*?)+\b(CAMERA)')
But It doesnt work. Can u help me ?
SHOT and CAMERA will always be the same. Only the NUMBER and the Letter before CAMERA can be different.

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 10 月 5 日
編集済み: Azzi Abdelmalek 2014 年 10 月 5 日
str='SHOT -31045 J CAMERA'
out=regexp(str,'\S\s+(CAMERA)','match')
out=out{1}(1)
%or if there are many cases
str='SHOT -31045 J CAMERA k CAMERA'
out=regexp(str,'\S\s+(CAMERA)','match')
out=cellfun(@(x) x(1),out,'un',0)
  2 件のコメント
Max Müller
Max Müller 2014 年 10 月 5 日
Thanks and i Guess i understand what u did there. This code searches for the backspace or empty space before Camera und gives back the Word Camera + the Letter before the backspace/empty space ?
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 10 月 5 日
Or
str='SHOT -31045 J CAMERA k CAMERA'
out=regexp(str,'\S(?=\sCAMERA)','match')

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


Guillaume
Guillaume 2014 年 10 月 5 日
編集済み: Guillaume 2014 年 10 月 5 日
Where did you get that regular expression from? It doesn't mean much with matlab's regexp engine (particularly the \b does not mean blank but backspace).
If you just want a single letter before CAMERA, you can just ignore everything before and the regular expression is just a letter ([A-Za-z] or just [A-Z] if just capital letters), plus at least one blank (\s+) plus camera:
s = 'SHOT -31045 J CAMERA';
letter = regexp(s, '([A-Za-z])\s+CAMERA', 'tokens', 'once')

カテゴリ

Help Center および File ExchangeMATLAB Support Package for IP Cameras についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by