Extracting numbers from string

1 vue (au cours des 30 derniers jours)
James Ang
James Ang le 4 Avr 2016
Commenté : James Ang le 5 Avr 2016
Hi,
I've some example strings:
CS-TZ24SKEW --> 24
CU-V18RKH-1 --> 18
CS-S24RKH-1 --> 24
CS-XC9RKD-3 --> 9
RS-PS9QK --> 9
CU-V18RWA --> 18
CS-KC18QKH-8 --> 18
CU-QA18RKH-8 --> 18
All I want to do is to extract the numeric values as shown on the right side of the respective strings. Is this possible with a couple of lines of code?
Thanks in advance.

Réponse acceptée

Walter Roberson
Walter Roberson le 4 Avr 2016
S = {'CS-TZ24SKEW', 'CU-V18RKH-1'};
extracted = regexprep(S, '^(\D+)(\d+)(.*)', '$2');
  1 commentaire
James Ang
James Ang le 5 Avr 2016
Thank you Walter!

Connectez-vous pour commenter.

Plus de réponses (1)

Kuifeng
Kuifeng le 4 Avr 2016

Catégories

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

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by