How to parse information between two strings using regular expressions?
14 次查看(过去 30 天)
显示 更早的评论
Hello,
I am trying to parse some information contained between the two strings "<sample>" and "</sample>" . I am new to regular expressions and would like to know what expression suits my requirement. The strings i mentioned have some operators in them. This is making the job difficult.
Regards, Math
2 个评论
Guillaume
2014-12-1
If you need more help than Thorsten's answer (which pretty much tells you everything that there is to it), then show us your current regular expression.
采纳的回答
Andrei Bobrov
2014-12-2
编辑:Andrei Bobrov
2014-12-2
str = '<sample>a,b,c</sample>';
out = regexp(str,'((?<=<sample>).*(?=<\/sample>))','match')
or
t = regexp(str,'<(|\/)sample>','splite')
out = t(~cellfun(@isempty,t))
0 个评论
更多回答(2 个)
Niels
2014-12-2
Alternatively, you may also consider using regexprep instead of regexp.
>> extract = regexprep(str,pat,'')
extract =
a,b,c
另请参阅
类别
在 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!