MATLAB Answers

find expression within {}

25 views (last 30 days)
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 Comments
Ajay krishna Vasanthakumar
i just want to to pick the chars inside {.*}.i dont want to pick /{.*} and append some varibales using regexprep.

Sign in to comment.

Accepted Answer

Rik
Rik on 20 Aug 2020
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 Comment
Ajay krishna Vasanthakumar
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 /.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!