Regular Expressions using regexp

조회 수: 3 (최근 30일)
Eduard Mazur
Eduard Mazur 2019년 5월 10일
편집: Stephen23 2019년 5월 10일
Hello, I have some problem with understanding regexp expression
I have some names: ["T_24_UZK500.txt"; "FWD_T80_UZK500.txt"; "T80_UZK700.txt"]
how can I get numbers after "T" and after "UZK"?
I need a rule that will describe only the numbers after the designated patterns.
  댓글 수: 2
Adam Danz
Adam Danz 2019년 5월 10일
Are "T" and "UZK" the only possible letters in the names?
Eduard Mazur
Eduard Mazur 2019년 5월 10일
편집: Eduard Mazur 2019년 5월 10일
It's variable symbols which are defined earlier.
I mean, I have filenames (string) and patterns (variable inside this names). With this information I need extract numerical vallues after variables..

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2019년 5월 10일
편집: Stephen23 2019년 5월 10일
Matching only integer numbers after 'UZK' or 'T_' (it is unclear in your question if the underscore is permitted or not, but the regular expression below is easy to adapt):
>> S = {'T_24_UZK500.txt';'FWD_T80_UZK500.txt';'T80_UZK700.txt'};
>> C = regexp(S,'(?<=(T_?|UZK))\d+','match');
>> C{:}
ans =
'24' '500'
ans =
'80' '500'
ans =
'80' '700'
Or simply by matching any integer numbers:
>> C = regexp(S,'\d+','match');
>> C{:}
ans =
'24' '500'
ans =
'80' '500'
ans =
'80' '700'
  댓글 수: 4
Eduard Mazur
Eduard Mazur 2019년 5월 10일
Thanks for your helping!
This solution fit for me.
madhan ravi
madhan ravi 2019년 5월 10일
Using exp as a variable name is not a good idea it would thwart the inbuilt function exp()

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by