distinguishing exponential (e) from other characters with regexp

6 次查看(过去 30 天)
omega=
'-1.86265e-09</'
'-1.86265e-09</'
'-1.74623e-09</'
'-1.74623e-09</'
'-1.62981e-09</'
'-1.62981e-09</'
'-1.74623e-09</'
'-1.62981e-09</'
'-1.86265e-09</'
'-1.62981e-09</'
'-1.86265e-09</'
%11x1 cell
I run the below code to extract only numeric parts of rows;
omega= regexp(omega,'[+-]?\d+\.?\d*', 'match');
But it also remove "e". How can I modify above code to get e as a numeric part?

采纳的回答

Stephen23
Stephen23 2017-5-24
编辑:Stephen23 2017-5-24
'[+-]?\d+\.?\d*([eE][+-]?\d+)?'
PS: If each string contains just one number then you should consider using the 'once' option as well, as this simplifies the outputs:
regexp(... 'match','once');

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by