find expression within {}

6 次查看(过去 30 天)
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
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
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 中查找有关 String Parsing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by