Problem: I have a string '01234(01)3423(32)' and I want to count the pattern of this string. I consider as pattern '0','1','2','3','4','(01)','3','4','2','3','(32)' --> pattern=11. If I use 'size' or 'length', this function count as pattern '(' '0' '1' ')' that i consider all togheter as one pattern '(01)'. Can you give me some suggestions to solve the problem?

 Respuesta aceptada

Stephen23
Stephen23 el 25 de Nov. de 2015
Editada: Stephen23 el 25 de Nov. de 2015

1 voto

Count the substrings:
>> S = '01234(01)3423(32)';
>> numel(regexp(S,'(\(\d+\)|\d)'))
ans = 11
And check that it matches the correct substrings:
>> regexp(S,'(\(\d+\)|\d)','match')
ans =
0
1
2
3
4
(01)
3
4
2
3
(32)
Tip
You should try using my FEX submission that helps you to create regular expressions:

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Preguntada:

el 25 de Nov. de 2015

Editada:

el 25 de Nov. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by