find expression within {}

조회 수: 25 (최근 30일)
Ajay krishna Vasanthakumar
Ajay krishna Vasanthakumar 2020년 8월 20일
편집: Ajay krishna Vasanthakumar 2020년 8월 20일
Hello all,
i have to fin {i++;} from the below expression using regexp.can some one help me out?
x = [task_queue[i] > 0 && i<NUM_FLOOR]{i++;}/{a =1;};
i tired using the below regexp
regexp(x,'[^/]\s*{.*}','match')
output : ']{i++;}/{a =1;}'
Thanks,
Ajay
  댓글 수: 2
Rik
Rik 2020년 8월 20일
Although you can do it with regexp, why would you? strfind will do the job here. What do you want to do with the result?
Ajay krishna Vasanthakumar
Ajay krishna Vasanthakumar 2020년 8월 20일
i just want to to pick the chars inside {.*}.i dont want to pick /{.*} and append some varibales using regexprep.

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

채택된 답변

Rik
Rik 2020년 8월 20일
You were close: you forgot to make the expression lazy, and you forgot you included the close bracket from the sting when excluding the / matched part.
str='x = [task_queue[i] > 0 && i<NUM_FLOOR]{i++;}/{a =1;};';
a=regexp(str,'[^/]({.*?})','tokens');
a{1}
  댓글 수: 1
Ajay krishna Vasanthakumar
Ajay krishna Vasanthakumar 2020년 8월 20일
편집: Ajay krishna Vasanthakumar 2020년 8월 20일
Thanks alot rik :)
i did a small correction to the expression
str='x = [task_queue[i] > 0 && i<NUM_FLOOR]{i++;}/{a =1;};';
a=regexp(str,'(?<!/\s*){.*?}','match');
a{1}
just to make sure the before letter is not followed by /.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Files and Folders에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by