how to remove a part which has specific char in the beginning and in the end in string?

1 view (last 30 days)
Hello,
how can I remove a part which has specific char in the beginning and in the end in string?
for example, if I have string like this:
cat dog zebra (squirrel) fish
and I want to remove a part which has '(' in the beggining and ')' in the end in order to get:
cat dog zebra fish
(without space char twice one after the other).

Accepted Answer

Stephen23
Stephen23 on 9 Nov 2020
str = 'cat dog zebra (squirrel) fish';
out = regexprep(str,'\s+\(.+?\)','')
out = 'cat dog zebra fish'

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!