distinguishing exponential (e) from other characters with regexp

5 vues (au cours des 30 derniers jours)
sermet
sermet le 24 Mai 2017
Modifié(e) : Stephen23 le 24 Mai 2017
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?

Réponse acceptée

Stephen23
Stephen23 le 24 Mai 2017
Modifié(e) : Stephen23 le 24 Mai 2017
'[+-]?\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');

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by