Is there a way to narrow down string searches to specfics integers/characters?
1 次查看(过去 30 天)
显示 更早的评论
I have a program that reads files and organizes them into structures. Unfortunately some of the files are not being read correctly because of the search. Here is an example on what string it searches for
Keyword = 'SLGN ';
Indices = strfind(Text, Keyword);
Instead I want to search for
Keyword = 'SLGN X,'
X being any integer or word. What I really want is that comma that is at the end of the phrase. Simply having SLGN with a space after it causes problems for some of the files since I'm trying to parse the lists rather than the paragraphs.
0 个评论
采纳的回答
Walter Roberson
2016-10-18
You do not speak about how you are doing the search. You can do that kind of matching with regexp()
Keyword = 'SLGN \w+,'
regexp(WhatYouAreSearching, Keyword)
you might want to add 'match' as an option, depending what you want to do with the result of the match.
7 个评论
Walter Roberson
2016-10-18
Keyword = 'SLGN\s+(\S+\s*,\s*)+\S+\s*$'
and add the option 'lineanchors'
This requires at least one comma and permits spaces before and after commas and permits the items to include any character except white space because the "(" followed by a word is required to match and so is word followed immediately by ")". So what it does not allow is if there is no comma or if there is a multiple word phrase between commas or a comma is the last non blank on the line.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!