How to search for substrings in a string?

1 visualización (últimos 30 días)
Peter Meier
Peter Meier el 22 de Jul. de 2020
Editada: Arthur Roué el 22 de Jul. de 2020
Hello,
I have a string ->
1583_pwer_exp_Exxxx_aqxxx_tqx_K2_vxxx_K101_
This string contains a substring (bold part - K1001) -> 1583_pwer_exp_Exxxx_aqxxx_tqx_K2_vxxx_K1001_
Letter K + an arbitrary (random) 4-digit number. I want to write out this 4 digit number.
Thx. :)
Here is my code:
my_strings="1583_pwer_exp_Exxxx_aqxxx_tqx_K2_vxxx_K1001_ "
tmp = regexp(my_strings,'(?<=_K)\d+','match','once');

Respuesta aceptada

Arthur Roué
Arthur Roué el 22 de Jul. de 2020
Editada: Arthur Roué el 22 de Jul. de 2020
You can specify that you want exactly 4 digits after '_K'
my_strings = '1583_pwer_exp_Exxxx_aqxxx_tqx_K2_vxxx_K1001_'
tmp = regexp(my_strings,'(?<=_K)\d{4}', 'match','once');

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by