How to parse information between two strings using regular expressions?
조회 수: 23 (최근 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!