find string pattern in strings ( 'ab*d' in 'abcd')
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jannis Maq
el 2 de Jun. de 2016
Comentada: Jannis Maq
el 3 de Jun. de 2016
Hello,
I want to check if there is a string pattern within a string. The pattern may look like this: 'ab*d', where * could be one or more charakters or none. So if the pattern would be 'abQWEd' or 'abd' I still want to have a positive feedback. Do you know how to do this?
Thanks!
0 comentarios
Respuesta aceptada
Elias Gule
el 2 de Jun. de 2016
try this:
pattern = 'ab.*d'; %%Pattern to match
textstr = 'sqthabVUYd'; %%Input string
match = regexp(textstr,pattern,'match');
this will match 'abVUYd' in the input string.
2 comentarios
Más respuestas (1)
Elias Gule
el 3 de Jun. de 2016
Editada: Elias Gule
el 3 de Jun. de 2016
I presume that you want it to work for all patterns 'ab.*d' that don't contain the letter "n" or "N", such that "abCDnMMd" does not produce a valid match while "abCDMMdn" does. If that's the case then, try this pattern:
pattern = 'ab((\W*[a-mA-Mo-zO-Z0-9]*\W*)*)d'; %%Pattern to match
*Note:
\W* => zero or more non-word characters
[a-mA-Mo-zO-Z]* => a group of zero or more upper or lowercase letters of the alphabet excluding "n" or "N".
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!