wilcard usage with strncmp
1 次查看(过去 30 天)
显示 更早的评论
I have a cell array data (C). I use the following code to find specific character in the C;
find_character = strncmp(C, '* 2020', 7);
How can I use wilcard using strncmp to find all patterns satisfy * [0-9][0-9][0-9][0-9]? For example, if * 1988 or * 2000 exist in C, they can be also extracted.
0 个评论
采纳的回答
Stephen23
2021-5-16
C = {'hello','* 2020','world','* 1923'};
X = ~cellfun(@isempty,regexp(C,'^\* \d{4}$'))
D = C(X)
4 个评论
Stephen23
2021-5-16
"How I can modify the above codes to work consistently with my cell array."
Remove the '$' from the end of the regular expression:
C = {'hello','* 2020 3 28','world','* 1923'};
X = ~cellfun(@isempty,regexp(C,'^\* \d{4}'))
更多回答(1 个)
Image Analyst
2021-5-16
Use the pattern functionality. I think it's easier than regexp().
>> doc pattern
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!