find strings between using regexp

I want to find all string inside of [ ], for example, I expect to get three results '1ac', 'd2' and 'k3' for following string
'[1ac][d2][k3]'
However, when I use
regexp('[1ac][d2][k3]','(?<=\[).+(?=\])','match')
I will get '1ac][d2][k3'.
How can I get three results '1ac', 'd2' and 'k3' instead?

 采纳的回答

Use extractBetween instead.
str = '[1ac][d2][k3]'
str = '[1ac][d2][k3]'
newStr = extractBetween(str,"[","]")
newStr = 3x1 cell array
{'1ac'} {'d2' } {'k3' }

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Characters and Strings 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by