Borrar filtros
Borrar filtros

How to find specific text in a string?

5 visualizaciones (últimos 30 días)
Mark Golberg
Mark Golberg el 4 de Abr. de 2022
Respondida: Cris LaPierre el 4 de Abr. de 2022
Hello,
I have the following text:
"abs(3).def(5).hhh(11)"
Is there an easy way for search for all the locations with "(" - number - ")".
I mean, all the places where there is a number between parenthesis.
I've try to use regexp but it was too complicate for me to understand how exactly it should be written.
Thanks.

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 4 de Abr. de 2022
I'm sure there is a regexp way to do this, but I find it easier to use pattern with its supporting functions. Here's how I would do it.
txt = "abs(3).def(5).hhh(11)";
pat = lookBehindBoundary("(") + digitsPattern + lookAheadBoundary(")");
extract(txt,pat)
ans = 3×1 string array
"3" "5" "11"

Más respuestas (1)

Fangjun Jiang
Fangjun Jiang el 4 de Abr. de 2022
a="abs(3).def(5).hhh(11)";
regexp(a,'(\d+)')

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