Remove "( )" from string words
Show older comments
Hi I need to Remove "()" from any word in DataBase.
My Database(cell) have string words such as:
'NEW' 'May' '(AFP)' 'US' 'prosecutors' 'on' 'Friday' 'unveiled' 'indictment' 'including' 'charges' 'of' 'murder' 'and' 'loan' 'sharking' 'against' . . . .
So, I need to Remove "(" and ")" from (AFP). because My word should be : AFP
Accepted Answer
More Answers (1)
Alberto
on 19 Oct 2014
You should use regexprep to replace anything that matches with parenthesis with an empty string; the pattern that matches any parenthesis shoul be:
pattern = '(\(|\))';
Its necessary to scape ( or ) using \( or \). See the examples:
>> texto = '(AFP)';
regexprep(texto, '(\(|\))', '')
ans =
AFP
>> texto = {'(AFP)','(cro'};
regexprep(texto, '(\(|\))', '')
ans =
'AFP' 'cro'
1 Comment
Guillaume
on 19 Oct 2014
Note that you don't need to surround the alternation with brackets and you don't need to escape the closing bracket, so this simpler pattern would work just as well:
pattern = '\(|)';
newdb = regexprep(db, pattern, '');
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!