Remove parenthesis and the contents inside from a string
    10 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Yuzhen Lu
 el 7 de En. de 2021
  
    
    
    
    
    Comentada: Stephen23
      
      
 el 9 de Mzo. de 2023
            Is there a neat way to remove a parenthesis and the contents inside from a string. For example the string 
A = 'abc (ABC)'
% how to extract 'abc' from A, get rid of ' (ABC)' including the leading whitespace?
One cumbersome solution is:
temp = strsplit(A,'(');
B = strtrim(temp(1));
0 comentarios
Respuesta aceptada
  Stephen23
      
      
 el 7 de En. de 2021
        A = 'abc (ABC)';
B = regexp(A,'^\w+','once','match')
5 comentarios
  Ivan Mich
 el 9 de Mzo. de 2023
				
      Editada: Ivan Mich
 el 9 de Mzo. de 2023
  
			Excuse me I have a question.. how could you do the inverse of this??
I mean to extract the only the characters that exist in brackets without the others.
for example:
input : A = 'abc (ABC)';
output B = 'ABC'
could you please help me?
  Stephen23
      
      
 el 9 de Mzo. de 2023
				"I mean to extract the only the characters that exist in brackets without the others."
A = 'abc (ABC)';
B = regexprep(A,{'.*\(','\).*'},'')
Más respuestas (1)
Ver también
Categorías
				Más información sobre Characters and Strings en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!