Replacing commas with whitespaces using regexprep

조회 수: 1 (최근 30일)
Raymond Wollenberg
Raymond Wollenberg 2019년 6월 18일
댓글: Raymond Wollenberg 2019년 6월 19일
Hello,
i am new to Matlab and really struggling with the regexprep function. I try to replace commas in brackets with whitespaces, so i can use the split function, without splitting my data in brackets.
Task:
str= '(asdf,(50,51,52),jklö)'
str_desired='(asdf,(50 51 52),jklö)'
I already found this:
exp='(?<=\()[^)]*(?=\))'
rep=' '
newstr=regexprep(str,exp,rep)= '( ),jklö)'+
But its not quite doing what i want, and i cant figure out how to place the hexadecimalvalue '\x2C' for comma.
Thank you very much!

채택된 답변

Stephen23
Stephen23 2019년 6월 18일
>> str = '(asdf,(50,51,52),jkl)';
>> regexprep(str,'(\d+),(\d+),(\d+)','$1 $2 $3')
ans = (asdf,(50 51 52),jkl)
If you are already using regexprep I don't see the point in using strsplit as well, you might as well just use regexp to split the string up.
  댓글 수: 6
Raymond Wollenberg
Raymond Wollenberg 2019년 6월 18일
Thank you very much again!
I already installed your tool on midday :D in hope I can use my problem with it. Thanks for explanation, i will dig into it tomorrow!
Raymond Wollenberg
Raymond Wollenberg 2019년 6월 19일
Worked out perfect, thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by