Regexp parentheses string parsing issue

조회 수: 3 (최근 30일)
Duke
Duke 2014년 3월 14일
편집: per isakson 2014년 3월 14일
I have a string that looks like:
'Hello (string_here.d) (string)'
I've messed with regexp for the last hour trying to get the 'string_here.d' from within the parentheses with no avail. I thought '([.]+)' or '\([.]+\)' would work, but them I thought it was the '.' causing me trouble so I tried '([.]+\.d)' and '\([.]+\.d\)'. I tried about 100 different variations of the above. What pattern would get me the string in the parentheses that has the . character in it.

채택된 답변

per isakson
per isakson 2014년 3월 14일
편집: per isakson 2014년 3월 14일
Not the most robust expression, but it works in this case
str = 'Hello (string_here.d) (string)';
cac = regexp( str, '(?<=\()\S+(?=\))', 'match', 'once' )
returns
cac =
string_here.d

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by