Effacer les filtres
Effacer les filtres

Correct use of regexp

2 vues (au cours des 30 derniers jours)
GEORGIOS BEKAS
GEORGIOS BEKAS le 13 Fév 2018
Commenté : GEORGIOS BEKAS le 13 Fév 2018
If x is the following string, I want to add a zero to the end of each sequence of zeros.
x='0110'
y=regexp(x,'[0+]','[0+]$0')
The result should be: x ='001100'

Réponses (2)

ES
ES le 13 Fév 2018
y=regexprep(x,'[0+]','00')
  1 commentaire
GEORGIOS BEKAS
GEORGIOS BEKAS le 13 Fév 2018
it does not work if the string would be: x='00011000'

Connectez-vous pour commenter.


Steven Lord
Steven Lord le 13 Fév 2018
x = char(randi([0 1], 1, 20)+'0')
y = regexprep(x, '0+', '$00')
J Smith's answer doubles the length of each run of 0's in x. Mine adds one 0 to the end of each run of 0's. In the case where all the runs are of length 1 they are the same. They aren't the same when you have runs of length greater than 1.
  1 commentaire
GEORGIOS BEKAS
GEORGIOS BEKAS le 13 Fév 2018
it does not work

Connectez-vous pour commenter.

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