Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Regular expressions - extract parts of a string

1 vue (au cours des 30 derniers jours)
Daniel Miller
Daniel Miller le 15 Oct 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hi!
I have a problem I'd need some help with.
I have the following code:
randomText = 'Madrid 2.7 Milano 3.85 Berlin 0.9 Lugano -2 Rome 12 Paris 9.2'
My task is to extract only the numbers (with dots included), and to do it I have written a code that looks like this:
Solution = regexp(randomText, '\d+\.\d+','match')
However, this only extracts the four numbers with dots (2.7, 3.5, 0.9 and 9.2) but ignores the -2 and the 12. How could I change my expression to extract all the numbers?
Thank you in advance for any help!

Réponses (0)

Cette question est clôturée.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by